I am trying to start Word from Excel to make a report using the following code snippet
Sub tempCreateWord() Dim objwordApp As New Word.Application Dim objwordDoc As Word.Document objwordApp.Visible = True Set objwordDoc = objwordApp.Documents.Add With objwordDoc .PageSetup.LeftMargin = CentimetersToPoints(1.5) .PageSetup.RightMargin = CentimetersToPoints(1.5) End With Set objwordDoc = Nothing End Sub
However the line “.PageSetup.LeftMargin = CentimetersToPoints(1.5)” bombs out with ther Error Msg
[indent]
Run-time error ‘462’:
The remote server machine does not exist or is unavailable
[/indent]
If Word is open before running the code it runs OK but if word is closed it gives the error about every other attempt to run it!
First try works OK. Close Word and run again it crashes, end the code close the copy of Word that it opened and run it again it will run OK.
I have checked in Task Manager in-between running it that there are no copies of Word running.
Any help appreciated
Peter