Results 1 to 5 of 5
  1. #1
    Silver Lounger
    Join Date
    Jun 2001
    Location
    Niagara Falls, New York, USA
    Posts
    1,877
    Thanks
    0
    Thanked 0 Times in 0 Posts

    ActiveX component can

    I

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 28 Times in 28 Posts

    Re: ActiveX component can

    GetObject causes an error if Word is not running. You should insert a line

    On Error Resume Next

    above the line with GetObject. You may want to insert

    On Error GoTo 0

    below the End If, or create an error handler for the second part (On Error GoTo SomeLabel)

  3. #3
    Super Moderator
    Join Date
    Aug 2001
    Location
    Evergreen, CO, USA
    Posts
    6,613
    Thanks
    3
    Thanked 58 Times in 58 Posts

    Re: ActiveX component can

    I'm not sure where you got the code you are working with, but it looks vaguely similar to some code in the Access Developer's Handbook that uses error handling to detect the run-time error 429 to figure out whether or not Word was already running. In point of fact, we normally assume that it is not running, and that seems to work just fine. Since you are dabbling in Automation, you might find our Automation Tutorial useful - and if you haven't downloaded the Automation Help files, you should do so post haste.
    Wendell

  4. #4
    4 Star Lounger
    Join Date
    Feb 2001
    Location
    Richland, Washington, USA
    Posts
    407
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: ActiveX component can

    John,

    Based on my experience with automation, it appears that your GetObject call would create the error if Word was not already open. I use error trapping to handle this situation. Something along the lines of:
    <font face="Georgia">
    Public Sub OpenWordDoc(strFilePath As String)

    Dim appWord As Object
    Dim doc As Word.Document
    Dim StartWord As Boolean

    On Error GoTo WordNotOpen

    Set appWord = GetObject(, "Word.Application")
    GoTo Continue

    WordNotOpen:

    Set appWord = CreateObject("Word.Application")
    If appWord Is Nothing Then
    MsgBox "Cannot activate Word.", vbCritical
    Exit Sub
    End If
    StartWord = True

    Continue:

    On Error GoTo 0

    Set doc = appWord.Documents.Open(strFilePath)
    appWord.Visible = True
    appWord.Activate
    Set appWord = Nothing
    Set doc = Nothing

    End Sub
    </font face=georgia>
    Hope this helps.

  5. #5
    Silver Lounger
    Join Date
    Jun 2001
    Location
    Niagara Falls, New York, USA
    Posts
    1,877
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: ActiveX component can

    Thank you Hans & Wendell

Posting Permissions

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