我创建了一个带有占位符(例如<>)的Word模板,然后可以使用我的Excel宏自动替换它们。当我再次尝试此过程时,Word文档现在打开并显示为只读文档。我该如何保存以便能够编辑Word模板?此外,当我通过我的Excel宏打开Word模板时,它如何知道将其另存为新的Word文档,而不是将其保存为更新的模板?
这是我的代码:
Sub ReplaceText()
Dim wApp As Word.Application
Dim wDoc As Word.Document
Set wApp = CreateObject("Word.Application")
wApp.Visible = True
Set wDoc = wApp.Documents.Open("file name here")
With wDoc
.Application.Selection.Find.Text = "<<name>>"
.Application.Selection.Find.Execute
.Application.Selection = Range("A5")
.Application.Selection.EndOf
.Application.Selection.Find.Text = "<<dob>>"
.Application.Selection.Find.Execute
.Application.Selection = Range("A6")
.SaveAs2 Filename:=("file name goes here"), _
FileFormat:=wdFormatXMLDocument, AddtoRecentFiles:=False
End With
End Sub