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 Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Writing to a word document 2

Status
Not open for further replies.

ndalli

Programmer
Nov 6, 1999
76
MT
I have written a print facility which first writes to a word document, closes this document and then opens it in a read only mode (to preview). In this way the user will be have all the options provided by word.

The problem happens when:
I first run the print process and when finished I will physically close the word document. On running the print process the second time I will get the error message:

run-time error 462
The remote server machine does not exist or is unavailable

The following is the code to write the document

'Activate The word application
Set WordApplication = CreateObject("Word.Application")
WordApplication.Visible = False
WordApplication.WindowState = wdWindowStateMinimize

'Creates a new document, saves it and then closes it
Documents.Add
ActiveDocument.SaveAs FileName:=Trim(strCreateFile)
WordApplication.Visible = False

Set myTable = ActiveDocument.Tables.Add(Range:=Selection.Range, NumRows:=6, NumColumns:= _
3, DefaultTableBehavior:=wdWord9TableBehavior, AutoFitBehavior:= _
wdAutoFitFixed)

.
.
.
ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
ActiveDocument.Close

DisplayBox = Documents.Open(strFileName, , ReadOnly)
WordApplication.Visible = True
WordApplication.WindowState = wdWindowStateMaximize

Can one please help.
Thanks in advance
 
Do not forget
WordApplication.Quit false ' Do not save changes
Set WordApplication = nothing
when quitting Word. Otherwise it hangs around.
When testing, set .Visible = true to see what is happening.
 
Hey ndali I have the exact same problem here...
And yes I use App.Quit and didn't forgot to set app=Nothing. This is preety weird what it seems to happen is that after opening word the 2nd time from the application it won't recognize the word objects. On my case I'm working with ListGalleries and if I try to open Word a 2nd time it'll open but it won't recognize the ListGalleries object giving me that error on the line where I try to refer to the ListGalleries:
run-time error 462
The remote server machine does not exist or is unavailable

Maybe we are both forgeting something, I don't know... Anyway if anyone could help I'd also appreciate it.
Meantime if I find out what's going on I'll let you know, and if could do the same for me I'd appreciate it.
 
Just for kicks, try GetObject(,"Word.Application") instead of CreatObject just to see if it makes a diffeence. The disadvantage is that it will use any already open WORD before it creates a new one. Have you tried duplicating this "manually" with Word. I only gotten "The remote server machine does not exist or is unavailable" when I used an object in VB that had a reference to WORD but I had "manually" made WORD disappear. Despite what I thought, holding a reference to an "out of process" server does not guarantee that it won't disappear for some reason.
Go to and enter Createobject Getobject in the Search field and search. There are some pertinent subjects such aa
 
ok, after some research I found out there is a bug causing this have a look at . The problem is I tryed to do what they suggested but, it still won't work...
The same error keeps appearing.
Anyway I think the automation thing is full of bugs on VB. I came up with another one today. If I have an OLE obj on my form and a variable to refer to it when I open a new word application and try to write something to it, it will write into the OLE Obj!! And I can't seem to work around this also anyone knows of any bug on this subject?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top