Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

run-time error 462 - remote server machine does not exist 2

Status
Not open for further replies.

KHerbs

Technical User
Apr 6, 2010
5
US
I have read several threads on the matter but my general lack of knowledge wrt VBA seems to be preventing me from adapting the answers to my situation.

I am running a macro in XL that loops through code designed to perform some calculations, paste the results to an XL tab, print that tab and open and print one of several word documents dependung upon the results. It keeps getting hung up the second time through when attempting to open the word document. It does not matter if the word document is the same as the first run or not.

Here is the code:

Dim AppWord As Word.Application
Dim mydoc As Word.Document

...

'Start Loop

...

' PRINT NOTES
Set AppWord = CreateObject("Word.Application")
AppWord.Visible = True
Set mydoc = Documents.Open(Filename:="filepathandname.docx", ReadOnly:=True)
AppWord.ActivePrinter = "Printer on Ne25:"
With AppWord
.ActiveDocument.PrintOut Background:=False
.Quit SaveChanges:=False
End With
Set AppWord = Nothing

...

End Loop

TIA!
 



Hi,
Code:
Set AppWord = CreateObject("Word.Application")
AppWord.Visible = True
Set mydoc = Documents.Open(Filename:="filepathandname.docx", ReadOnly:=True)
AppWord.ActivePrinter = "Printer on Ne25:"

   mydoc.PrintOut Background:=False
   mydoc.Close SaveChanges:=False

   AppWord.Quit 

Set mydoc = nothing
Set AppWord = Nothing


Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Set mydoc = [!]AppWord.[/!]Documents.Open(Filename:="filepathandname.docx", ReadOnly:=True)

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Thanks, that is working. My only remaining issue is I now have x instances of Word open when it finishes running. How do I get Word to close (either throughout the process or all at once at the end)?
 
PHV's solution worked and did not result in multiple instances of Word being left open.

Thanks.
 
I have a follow-up question with respect to the solution above. Whenever I run this macro my default printer (for all programs) is reset to the printer identified in the code. Is there a way to prevent this from occuring because it is somewhat annoying? I should also add that I will not be the only person to run this macro from the exact same file so adding a line at the end to reset the printer to somehting else would not work correctly for everyone.
 




Change it back to the original before exiting.

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 



Normally, when one changes a global sonething temproarily, one...

1. Save the original something

2. set the temporary something

3. persorm the process

4. reset the something to the original something, using the saves value.

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
That is wonderful. Unfortunately, as I mentioned in my initial post, I have extremely limited knowledge of VBA. Would you care to elaborate on how I can do items 1 and 4?
 


Code:
Dim sOriginal as string
'save original setting
sOriginal = AppWord.ActivePrinter

AppWord.ActivePrinter = "Printer on Ne25:"

'stuff

'restore original setting
AppWord.ActivePrinter = sOriginal

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top