-
OLE Ms Word
Hello,
I have started programming vb6 about a month ago and i have runin to a little bit of a problem. I want to open Ms Word with a new document and setup this document through my vb6 program. The first time vb6 opens Ms Word there is are no errors and Word is started, but when Ms Word is closed and i run the code for the second time i get this error message:
RUN TIME ERROR the remote machine does not exits or is unavailable.
Thanx for your time !,
This is the code:
Public objWord As Word.Application
Private Sub cmdStart_Click()
Dim range1 As Range
Dim DocNaam As String
Dim DezeDoc As Document
Set objWord = new Word.Application
objWord.Visible=True
With objWord
.documents.Add
DocNaam = .ActiveDocument.Name
set DezeDoc = .Documents(DocNaam)
set range1 = DezeDoc.Range
range1.InsertAfter "test"
range1.PageSetup.Topmargin = CentimetersToPoints (3.5)
End With
End Sub
-
Hi kabouter do some exercises and you won't be that stram any more.
I think it should be better to close the word application when the form using it is unloaded.
And set the object with an instance of it to nothing.
-
doent look like you closed msword either, if you open it than you have to close it and destroy the object, (from reply above me)
-
Hi,
Quit the instance of the word u are using as shown below to avoid the error.
'------------------------------------------------------------------------------
objWord.Quit
Set objword = Nothing
----------------------------------------------------------------------------------