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
Highlighted
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
Highlighted
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
[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
Highlighted
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

Learn SmartBear products in a fun and easy way and prove your knowledge!
>>Participate in the TechCorner Challenge today
Highlighted
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

Highlighted
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

Learn SmartBear products in a fun and easy way and prove your knowledge!
>>Participate in the TechCorner Challenge today
New Here?
Join us and watch the welcome video:
Announcements
Join TechCorner Challenge!
Want a fun and easy way to learn TestComplete? Try solving weekly TechCorner challenges and get into the Leaderboard!


Challenge Status

Compare images using the Region Checkpoint

See replies!

Converting UTC TimeDate in an Excel file

See replies!

Compare HTML table with Excel file and correct data in Excel file

Participate!

How to execute remote test and obtain results via Test Runner REST API

Participate!
Top Kudoed Authors