Results 1 to 3 of 3
  1. #1
    New Lounger
    Join Date
    Aug 2003
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Follow-Up to VB6-Word Question (Word 2003 Beta/VB6)

    First, I would like to apologize for any confusion that I may have caused by posting the same question in two forums. I post this follow-up here because it may be more of a Word question than a VB6 question given the answer I received from Hans.

    The code Hans gave me worked perfectly, actually too well. By removing Word from memory, the Word documents that I created were closed. To more precisely define my question, each time that I ran my VB6 program (which creates letters) it would open a separate Winword.exe as shown by my Task Manager. Is it possible to write cord where it looks to see if Winword is all ready open when the program loads? If open, perhaps it could forego executing another Winword. I apologize for the awkwardness of my question, but this is not my area. Again, I greatly appreciate any and all suggestions! Thanks!

    Bob Nichols

  2. #2
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Follow-Up to VB6-Word Question (Word 2003 Beta/VB6)

    Bob, the CreateObject() method is what generates a new instance of an application.

    You can cause VB to re-use a running instance of the application with the GetObject method. If that fails, you get a predictable error code, so VB detects that error, you then can use CreateObject().

    The above is not specific to Word, but works with all Office applications and many others. Some examples:

    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

    Subject: Re: New Word Object (Word 2000/02) [#240750]
    Poster: HansV
    Posted on: 02-Apr-03 19:46

    I use code like this; perhaps you can adapt it for your own use. It's easy to adapt for Excel, Outlook, PowerPoint too.

    Dim blnNotActive As Boolean
    Dim objWordApp As Word.Application

    ' No error messages here
    On Error Resume Next

    ' Check whether Word is active
    Set objWordApp = GetObject(, "Word.Application")
    blnNotActive = (Err <> 0)
    If blnNotActive Then
    ' If not, we start Word
    Err.Clear
    Set objWordApp = CreateObject("Word.Application")
    End If

    ' Resume standard error handling here
    On Error GoTo Err_Handler ' or GoTo 0 if you don't handle it yourself

    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

    <post#=272391>post 272391</post#> - automating Outlook

  3. #3
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Follow-Up to VB6-Word Question (Word 2003 Beta/VB6)

    To avoid closing Word, edit or remove this line

    objWordApp.Quit SaveChanges:=wdDoNotSaveChanges

    from the solution Hans provided in <post#=289580>post 289580</post#>. As the method name implies, this is what is causing the Word Application to Quit.

    For future reference, it is best to simply raise this kind of issue in the same thread, otherwise people here have no idea what code you're talking about. <img src=/S/smile.gif border=0 alt=smile width=15 height=15>

Posting Permissions

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