cancel
Showing results for 
Search instead for 
Did you mean: 

How to SaveAs a word doc which is already open

SOLVED
Highlighted
New Contributor

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.

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
New Contributor

Re: How to SaveAs a word doc which is already open

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.

View solution in original post

4 REPLIES 4
Community Hero

Re: How to SaveAs a word doc which is already open

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
[Community Expert Group]
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
Community Manager

Re: How to SaveAs a word doc which is already open

Thank you for help tristaanogre! 

Hi @sim2020 , did you solve the issue?   



Sonya Mihaljova
Community and Education Specialist

 Join SmartBear Connect next April in Boston to meet with software development, API and testing experts from around the world! Get your ticket today!
New Contributor

Re: How to SaveAs a word doc which is already open

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.

View solution in original post

Community Manager

Re: How to SaveAs a word doc which is already open

Great to hear you’ve found a workaround!



Sonya Mihaljova
Community and Education Specialist

 Join SmartBear Connect next April in Boston to meet with software development, API and testing experts from around the world! Get your ticket today!