How to SaveAs a word doc which is already open
SOLVED- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
How to SaveAs a word doc which is already open
My application opens up a word document in preview mode. I'm trying to close the preview mode, then it opens the file in a compatibility mode. I need to save as the file in a folder.
I've tried like this:
Sys.Process("WINWORD", 2).Close - This closes the preview mode
If (Sys.Process("WINWORD").Exists) Then
Set WordObject =Sys.OleObject("Word.Application")
WordObject.ActiveDocument.SaveAs("C:\work.doc")
End If
I get an error in the 'WordObject.ActiveDocument.SaveAs("C:\work.doc")' statement 'This command is not available because no document is open'
How can I handle this? Any help would appreciate.
Solved! Go to Solution.
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Sys.OleObject doesn't use an exsisting process of Word but actually creates a new instance. So, your WordObject is a different instance than the running Word instance hence why it doesn't think there is doc open.
Suggested change... no guarentees, just a suggestion.
Sys.Process("WINWORD", 2).Close - This closes the preview mode Set WordObject = Sys.WaitProcess('WINWORD") If (WordObject.Exists) Then WordObject.ActiveDocument.SaveAs("C:\work.doc") End If
Robert Martin
[Hall of Fame]
Please consider giving a Kudo if I write good stuff
----
Why automate? I do automated testing because there's only so much a human being can do and remain healthy. Sleep is a requirement. So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.
Mysterious Gremlin Master
Vegas Thrill Rider
Extensions available
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thank you for help tristaanogre!
Hi @sim2020 , did you solve the issue?
Sonya Mihaljova
Community and Education Specialist
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks, @tristaanogre for the reply. That didn't work, unfortunately. I have managed to find the temp file in a folder and take a copy of that as a solution to my issue.
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Great to hear you’ve found a workaround!
Sonya Mihaljova
Community and Education Specialist
