开发者

Open a word document and save it to another folder with vbscript

I have working code that opens up a word document programmatically using vbscript, makes a change, then saves that same document and closes that same document.

Is it possible to do the same thing, but save the document to another folder and close out both instances of word? I slightly modified my original code, but it only closed out the second instance of the word document tha开发者_JAVA技巧t was saved.

Apparently, word thinks if I'm saving to another folder it needs 2 instances of the document. This is some of my original code:

Set objDoc = objWord.Documents.Open(objFile.Path)
'modify the document.
etc...

objDoc.SaveAs objFSO.BuildPath(strDirectory, objFSO.GetFileName(objFile.Path))
objDoc.Close

this works fine for one document. Then all I changed was this, adding another directory to write to instead of the original:

objDoc.SaveAs objFSO.BuildPath(strDirectory & saveDir,  objFSO.GetFileName(objFile.Path))

and I ended up with two identical word documents opened and when I closed the one I was saving, the other stayed open.

Is there a simple way to do this?

Thanks,

James


It may be better to save the word document in the original folder and then write further code to move it into another location, perhaps using FileSystemObject.MoveFile. Don't rely on Word's "Save-as" functionality to do this - as you have observed you get a nasty side-effect.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜