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文檔的所有標題