0
Sub ReplaceEntireHdr()
Dim wrd As Word.Application
Set wrd = CreateObject("word.application")
wrd.Visible = True
AppActivate wrd.Name
'Change the directory to YOUR folder's path
fName = Dir("C:\Users\user1\Desktop\A\*.doc")
Do While (fName <> "")
With wrd
'Change the directory to YOUR folder's path
.Documents.Open ("C:\Users\user1\Desktop\A\" & fName)
If .ActiveWindow.View.SplitSpecial = wdPaneNone Then
.ActiveWindow.ActivePane.View.Type = wdPrintView
Else
.ActiveWindow.View.Type = wdPrintView
End If
.ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
.Selection.WholeStory
.Selection.Paste
.ActiveDocument.Save
.ActiveDocument.Close
End With
fName = Dir
Loop
Set wrd = Nothing
End Sub
我使用此vba代码替换文件夹“A”中所有文档的所有标题。但是,如果父文件夹“A”中的任何子文件夹含有word文档,vba代码将跳过这些文档。任何人都可以请告诉我如何在子文件夹中包含word文档?也许通过对代码或任何其他可以完成相同工作的vba代码进行一些更改。 在此先感谢。创建vba代码来替换文件夹和子文件夹中所有word文档的所有标题