作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我创建了一个带有占位符(例如 <>)的 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
最佳答案
虽然 @wahwahwah 的方法有效,但它仍然将模板作为文档打开进行编辑,然后以其他格式保存,同时抑制警报。我怀疑您想要实现的是从外壳打开模板时的行为,它会根据模板生成"new"文档。您可以使用“添加”方法来实现此目的;
Set wDoc = wApp.Documents.Add(Template:="file path here", NewTemplate:=False, DocumentType:=0)
关于vba - Excel VBA 打开 Word 模板,填充,然后在其他位置另存为 .docx 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26042519/
我有 json 数据: { "products": [ { "productId" : 0, "productImg" : "../img/product-ph
我是一名优秀的程序员,十分优秀!