用于保存当前打开的 Word 文档的 VbScript [英] VbScript to save a current open Word document
本文介绍了用于保存当前打开的 Word 文档的 VbScript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嗨我想让 vbscript 保存当前打开的 Word 文档,我正在使用代码:
hi I want vbscript to save a current open Word document, I am using the code:
Dim objWord As Object
Set objWord = CreateObject("Word.Application")
Set objDoc = objWord.Documents.Add()
objDoc.Save
但它正在打开一个新的 Word 文档,然后要求我保存.
but it is opening a new word document and then asking me to save.
我的要求是我创建了一个菜单按钮,如果文档已经保存在某个位置,它应该保存所做的更改,否则它应该询问我路径并将其保存在那里
My requirement is i have created a menu button on click of it if the doc is already saved at a location it should save the changes made or if it is not it should ask me the path and save it there
谢谢创作者
推荐答案
我不得不做同样的事情,这就是我使用的:
I had to do the same thing and this is what I used:
' Create the File System Object
Set objFSO = CreateObject("Scripting.FileSystemObject")
'Check for directory folder.
If objFSO.FolderExists(strDirectory) Then
Set objFolder = objFSO.GetFolder(strDirectory)
Set objWord = CreateObject("Word.Application")
objWord.Visible = True
Set objDoc = objWord.Documents.Open(objFile.Path)
objDoc.SaveAs objFSO.BuildPath(strDirectory, objFSO.GetFileName(objFile.Path))
objDoc.Close
etc...
您必须填写其余部分并初始化变量,但这是有效的代码.
You will have to fill in the rest and init the variables, but this is working code.
HTH,
詹姆斯
这篇关于用于保存当前打开的 Word 文档的 VbScript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文