Passing Userforms to subs (Word 2000 and 2002, I did not try Word 97) 
Author Message
 Passing Userforms to subs (Word 2000 and 2002, I did not try Word 97)

In order to access the Caption of a Userform in a Sub, I must pass the
Userform as an Object, instead of as a Userform.
In addition, if I do pass the Userform as a Userform, instead of as an
Object, setting the Caption in the Sub causes the text to appear in the body
of the Userform, instead of the Title bar. For example:

1. Create a Userform with 3 buttons:

    btnFinish: Caption "Finish"
    btnPushMe: Caption "Push me!"
    btnPushMeToo: Caption "Push me too!"

2. Create a module with a sub ResetCaption with the following code:

Option Explicit
'Public Sub ResetCaption(Optional frmCurrent As MSForms.UserForm = Nothing)
Public Sub ResetCaption(Optional frmCurrent As Object = Nothing)
    If frmCurrent Is Nothing Then
        frmSetUserformCaption.Caption = "Bagels and lox is really good
        frmCurrent.Caption = "Pizza is yummy too!!"
    End If
End Sub

3. Use the following code in the Userform:

Option Explicit

Private Sub btnFinish_Click()
    Unload Me
End Sub

Private Sub btnPushMe_Click()
End Sub

Private Sub btnPushMeToo_Click()
    ResetCaption Me
'    ResetCaption frmSetUserformCaption
End Sub

I get the same result using either Me or the Userform name, in my case,

The corresponding code works properly in both VB and VB .Net passing a Form
instead of an Object.
http://www.*-*-*.com/ ; Programming and support for  Word macros,
including converting from WordBasic to VBA; Technical reviewing; Standards;
Product functional/design/specifications

Fri, 26 Nov 2004 06:57:05 GMT  
 [ 1 post ] 

 Relevant Pages 

1. Word 2002: How to save a file in Word 97 format in Word 2002

2. Word 2000/2002/97 compatability

3. Why does this piece of code work with Word 97 but not Word 2000

4. vba problem word 97 and not word 2000

5. Going from Word 97 to Word 2002 (Macros)

6. VBA in a workgroup template runs slower on Word 2002 than on Word 97

7. Question for Microsoft about Word 2000 and Word 2002

8. Word 2002 Template won't open in Word 2000

9. Differences on word 2002 and word 2000 vba

10. Does Word VBA 2002 developed code run on Word 2000

11. Problem between version Word 2000 and Word 2002

12. Macro: Bug, or "resource" limit, in Word 2002, works in Word 2000 and Word 97


Powered by phpBB® Forum Software