Results 1 to 4 of 4

Thread: OLE Ms Word

  1. #1

    Thread Starter
    New Member
    Join Date
    Jul 2002
    Location
    The Netherlands
    Posts
    4

    Question 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

  2. #2
    Swatty
    Guest
    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.

    VB Code:
    1. Set objWord = Nothing

  3. #3
    Lively Member
    Join Date
    Jul 2000
    Location
    Lost in the Mojave Desert
    Posts
    82
    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)
    Don't go away mad, just go away.

    Bam-Bam

  4. #4
    Addicted Member
    Join Date
    Nov 2001
    Posts
    181
    Hi,
    Quit the instance of the word u are using as shown below to avoid the error.
    '------------------------------------------------------------------------------
    objWord.Quit
    Set objword = Nothing

    ----------------------------------------------------------------------------------

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width