Consulting

Results 1 to 14 of 14

Thread: Open Userform From a Macro

  1. #1
    VBAX Expert
    Joined
    Jan 2005
    Posts
    574
    Location

    Open Userform From a Macro

    I need to be able to open a userform from a template in word97

    I can do it in word 2000 with the On New command but this doesnt work in word 97

    Is It possible in word 97?

    If so how

    Help!!!!!!!

  2. #2
    Site Admin
    Jedi Master
    VBAX Guru Jacob Hilderbrand's Avatar
    Joined
    Jun 2004
    Location
    Roseville, CA
    Posts
    3,712
    Location
    You can use this to open the UserForm.
    [vba]
    UserFormName.Show
    [/vba]
    If you want it to automatically run when the template is opened then you need to check what events are available. Its been a while since I have used Office 97 so I am not 100% sure what events are available to you. Go to the VBE and double click on ThisDocument. From the left drop down (above the Code Window) select Document. From the right drop down see if there is an event you can use like New or Open.

  3. #3
    VBAX Expert
    Joined
    Jan 2005
    Posts
    574
    Location
    Thanks Jake, thats what I have but wont work on word 97, i was wondering if the on new command only became available in word 2000? the other thing i considered is I created the template in word 2000 so maybe thats my problem?

    Any ideas

  4. #4
    Site Admin
    Jedi Master
    VBAX Guru Jacob Hilderbrand's Avatar
    Joined
    Jun 2004
    Location
    Roseville, CA
    Posts
    3,712
    Location
    Open a new doc in Word 97 and check the events. Are there any available?

  5. #5
    VBAX Mentor
    Joined
    Sep 2004
    Location
    Nashua, NH, USA
    Posts
    489
    Location
    Quote Originally Posted by DRJ
    You can use this to open the UserForm.
    [vba]
    UserFormName.Show
    [/vba]
    If you want it to automatically run when the template is opened then you need to check what events are available. Its been a while since I have used Office 97 so I am not 100% sure what events are available to you. Go to the VBE and double click on ThisDocument. From the left drop down (above the Code Window) select Document. From the right drop down see if there is an event you can use like New or Open.
    Word 97 is nearly brain dead as far as application events are concerned.

  6. #6
    VBAX Tutor
    Joined
    May 2004
    Location
    Germany, Dresden
    Posts
    217
    Location
    This one should work in the template in Word97:
    [VBA] Option Explicit

    Private Sub Document_New()

    UserForm1.Show

    End Sub[/VBA]

  7. #7
    VBAX Mentor
    Joined
    Sep 2004
    Location
    Nashua, NH, USA
    Posts
    489
    Location
    Quote Originally Posted by gibbo1715
    Thanks Jake, thats what I have but wont work on word 97, i was wondering if the on new command only became available in word 2000? the other thing i considered is I created the template in word 2000 so maybe thats my problem?

    Any ideas
    What is the "On new" command?

    It's not in the object browser.

  8. #8
    VBAX Expert
    Joined
    Jan 2005
    Posts
    574
    Location
    in word 2000 as well as the onopen() event there is an Onnew() event that will run a macro from a template when creating a new document, doesnt seem to be available in word 97

  9. #9
    VBAX Master TonyJollans's Avatar
    Joined
    May 2004
    Location
    Norfolk, England
    Posts
    2,291
    Location
    gibbo,

    It would help if you were precise in your terminology (unless you are, and there's something none of us know).

    The Document_New Event exists in Word 97. What makes you think it doesn't?

    The AutoNew macro can also be used.

    As Howard so succinctly said, Word 97 is a bit lacking in Application events (although it does have a DocumentChange event which will fire) but you don't need to use them for this.
    Enjoy,
    Tony

    ---------------------------------------------------------------
    Give a man a fish and he'll eat for a day.
    Teach him how to fish and he'll sit in a boat and drink beer all day.

    I'm (slowly) building my own site: www.WordArticles.com

  10. #10
    VBAX Mentor
    Joined
    Sep 2004
    Location
    Nashua, NH, USA
    Posts
    489
    Location
    Quote Originally Posted by gibbo1715
    in word 2000 as well as the onopen() event there is an Onnew() event that will run a macro from a template when creating a new document, doesnt seem to be available in word 97
    That's Document_New and Document_Open events, not OnOpen or OnNew commands.

    If you need to do serious Word VBA, you really do need Word 2000 or later.

  11. #11
    VBAX Wizard
    Joined
    May 2004
    Posts
    6,713
    Location
    Is Word 97 even VBA? I thought it was still WordBasic. Silly me, but then I have never used 97. However, as Tony points out, AutoOpen and AutoNew macros have been around a while. Since Word 3.0 I believe.

  12. #12
    VBAX Expert
    Joined
    Jan 2005
    Posts
    574
    Location
    managed to get it working (sort of), word 97 is not that useful when using code is it!!! roll on when my company has completely migrated to word 2000


    Thanks for all your help guys

  13. #13
    VBAX Tutor
    Joined
    May 2004
    Location
    Germany, Dresden
    Posts
    217
    Location
    And Gerry, believe it or not, Word97 has VBA
    (I think it was the first Word to have it) because only 3 years ago I should migrate an application running under Word 6 (WordBasic) to 97 .

    Fortunately, I could convince my boss that creating a new Software from the scratch using VB 6 & VBA would be far more effective.

  14. #14
    VBAX Mentor
    Joined
    Sep 2004
    Location
    Nashua, NH, USA
    Posts
    489
    Location
    Quote Originally Posted by fumei
    Is Word 97 even VBA? I thought it was still WordBasic. Silly me, but then I have never used 97. However, as Tony points out, AutoOpen and AutoNew macros have been around a while. Since Word 3.0 I believe.
    Word 97 was the first VBA version of Word.

Posting Permissions

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