Results 1 to 6 of 6

Thread: VB6

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

    VB6

    I am an attorney which right away indicates I need help!

    I utilize VB6 to insert information gathered from a number of textboxes, comboboxes etc. into Microsoft Word Document Templates. Lately, I have been getting an error when closing those documents that states that the NormalTemplate must be saved and other messages stating that it is a read only document. I must continuously close both message boxes and sometimes the VB6 program ceases to function. This happens when I prepare several documents each time opening Microsoft Word as follows:

    Set ObjWord = CreateObject("Word.Basic")
    With ObjWord

    The module ends with:

    End With
    Unload ObjWord
    End
    End Sub

    Each time I utilize the programs it opens WinWord.exe so I have as many of those as I do documents prepared, even after VB6 is closed. I suspect this might be my problem. Is there another way to open and close Word that might help. I greatly appreciate any assistance! Thanks!

    Robert E. Nichols
    Attorney at Law

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

    Re: VB6

    Word.Basic is an object only meant for compatibility with old versions of Word (up to Word 95, if I remember correctly). Since the Office 97 version, Word has used Visual Basic for Applications (VBA). You will have to rewrite your code to use VBA instead of WordBasic.

    To get your code to run in VBA with a minimum of modifications, set a reference (In Project | References...) to the Microsoft Word 11.0 Object Library (11.0 is the version for Office 2003) and use a code outline as follows:

    Sub Something
    Dim objWordApp As Word.Application
    Dim objWord As Word.WordBasic

    On Error GoTo ErrHandler

    Set objWordApp = CreateObject("Word.Application")
    Set objWord = objWordApp.WordBasic

    With objWord
    ' your code here
    End With

    ExitHandler:
    ' Clean up and remove Word from memory.
    On Error Resume Next
    Set objWord = Nothing
    objWordApp.Quit SaveChanges:=wdDoNotSaveChanges
    Set objWordApp = Nothing
    Exit Sub

    ErrHandler:
    MsgBox Err.Description, vbExclamation
    Resume ExitHandler
    End Sub

  3. #3
    Silver Lounger
    Join Date
    Jul 2001
    Location
    Ottawa, Ontario, Canada
    Posts
    1,609
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: VB6

    Hans
    I have some legacy code in a rather lengthy project which I wrote some 10+ years ago in WordBasic for Word 6. The code has been tweaked over the years in VBA, first with Word 97 and later Word 2000. Now we have moved to Office 2003 and I am having some difficulty with the code hanging immediately after a WordBasic command.
    Methinks it is time to weed out all of the old WordBasic code and work exclusively in VBA. Further I believe that the code you have posted here is the way to go; though I'm not sufficiently comfortable to march in with full confidence. Any words of wisdom?

    TIA
    Regards
    Don

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

    Re: VB6

    The code in my reply from almost exactly 2 years ago was meant to use WordBasic from a VB6 application. If you want to convert to VBA, you will have to use the VBA for Word help file extensively to try and find what the nearest equivalent of each WordBasic statement is. That's a lot of work!

  5. #5
    Silver Lounger
    Join Date
    Jul 2001
    Location
    Ottawa, Ontario, Canada
    Posts
    1,609
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: VB6

    Thanks for the guidance Hans. This should keep me off the streets at night for a while.
    Regards
    Don

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

    Re: VB6

    <img src=/S/nosleep.gif border=0 alt=nosleep width=27 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
  •