0

我有以下宏代码。但是,它不通过子目录。谁能告诉我如何编辑它以便它这样做?

Sub ChangeTemplates()
Dim strDocPath As String
Dim strTemplateB As String
Dim strCurDoc As String
Dim docCurDoc As Document

' set document folder path and template strings
strDocPath = "C:\Users\servicedesk\Desktop\Test\"
strTemplateB = "C:\Users\servicedesk\Desktop\Blanco.dotx"

' get first doc - only time need to provide file spec
strCurDoc = Dir(strDocPath & "*.doc")

' ready to loop (for as long as file found)
Do While strCurDoc <> ""
    ' open file
    Set docCurDoc = Documents.Open(FileName:=strDocPath & strCurDoc)
    ' change the template
    docCurDoc.AttachedTemplate = strTemplateB
    ' save and close
    docCurDoc.Close wdSaveChanges
    ' get next file name
    strCurDoc = Dir
Loop
MsgBox "Finished"
End Sub
4

1 回答 1

0

您需要修改脚本以将循环文件的部分提取到它自己的函数中,然后在遇到文件夹时递归调用此函数。

页面上的脚本演示了如何实现此目的。

于 2013-12-02T19:53:14.480 回答