[英]Open with Excel VBA a Word document, add some data and just save it (the Word document)
我正在使用 Excel VBA 打开一个预先存在的 word 文档并向其中添加一些数据,然后我只想保存这个文件。 但是当我运行 Excel VBA 宏时,会出现“另存为”窗口。
这不是我的目标。
word文档应该只是保存...(例如当您手动将一些数据添加到word文档然后按CTRL + S)
如果需要更多详细信息,请告诉我......非常感谢您提前提供的帮助。
现在我的代码:
Dim appWord As Word.Application
Dim document As Word.Document
Set appWord = CreateObject("Word.Application")
' the excel file and the word document are in the same folder
Set document = appWord.Documents.Add( _
ThisWorkbook.Path & "\Testfile.docx")
' adding the needed data to the word file
...
' in this following line of code I tried to do the correct saving... but it opens the "save as" window - I just want to save it automatically
document.Close wdSaveChanges = -1
'Close our instance of Microsoft Word
appWord.Quit
'Release the external variables from the memory
Set document = Nothing
Set appWord = Nothing
Set document = appWord.Documents.Add( _
ThisWorkbook.Path & "\Testfile.docx")
您不是使用此代码打开文档,而是从现有文档创建一个未保存的新文档。 将其更改为:
Set document = appWord.Documents.Open( _
ThisWorkbook.Path & "\Testfile.docx")
您还缺少一个冒号。
document.Close wdSaveChanges:=-1
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.