
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
too!!"
Else
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()
ResetCaption
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,
frmSetUserCaption.
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
------------------------------------------------