PDA

View Full Version : [SOLVED:] Word doc - Save & SaveAs from Excel



BrI
06-08-2017, 12:29 PM
Working from excel, I want to Save an already open Word doc and then do a SaveAs to a new directory. Both docs should be closed when finished.

The following are my beginning efforts, I'm having problems as indicated.


Sub SaveWordFromExcel()


Dim objWord
Set objWord = CreateObject("Word.Application")

Dim objDoc As Object

objWord.Visible = True

'The doc is already open, but tried using ".Open" as below to get file path reference
'Result is dialog box saying "File In Use .... Do you want to open read only"
Set objDoc = objWord.Documents.Open("C:\***x\Word Test 1.doc")

objDoc.Save

objDoc.SaveAs ("F:\***x\Word Test 1.doc")

End Sub


Any assistance would be appreciated.

mdmackillop
06-09-2017, 04:02 AM
Sub SaveWordFromExcel()
Dim objWord
Dim objDoc As Object
Set objWord = GetObject(, "Word.Application")
objWord.Visible = True
'As the document is open
Set objDoc = objWord.Documents("Test.doc")
With objDoc
.Save
.SaveAs ("C:\VBAX\Test 1.doc")
.Close
End With
objWord.Quit
End Sub

BrI
06-09-2017, 07:33 AM
That works perfectly! Thanks, really appreciate it!