【发布时间】:2018-04-09 19:08:34
【问题描述】:
我创建了一个带有诸如 之类的占位符的单词模板,然后我可以用我的 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
【问题讨论】: