Connect form's initialize event to a toolbar button

S

Sammy

Hello, I'm using Word 03. I have a global template in my startup folder
which contains a company toolbar and associated macros. I'm trying to
create a form and associated code inside the global template so that when a
user clicks on the toolbar button, the form appears to allow the user to make
a selection and click OK (or cancel). When I go to customize the toolbar to
add the button, my initialize macro doesn't show up, I'm not sure what I am
missing. Do I need a macro in the NewMacros module of the global template to
open the form? Can you help me? thanks

I have the following code behind the form:

Private Sub btnOK_Click()
btnOKclicked = True
Me.Hide

End Sub

Private Sub btnCancel_Click()
btnOKclicked = False
Me.Hide

End Sub


Public Sub UserForm_Initialize()

With frmNumber
..opt1 = True
..opt1.SetFocus
End With

frmNumber.Show

End Sub



'NumOut1, 2 and 3 are the macros a user can select from the form.
Sub NumOut1()
ActiveDocument.CopyStylesFromTemplate Template:= _
"E:\Demo\Style Sheets\#1 Style Sheet.dot"
CommandBars("Paragraph Numbering").Visible = True
End Sub

Sub NumOut2()

ActiveDocument.CopyStylesFromTemplate Template:= _
"E:\Demo\Style Sheets\#2 Style Sheet.dot"
CommandBars("Paragraph Numbering").Visible = True

End Sub

Sub NumOut3()

ActiveDocument.CopyStylesFromTemplate Template:= _
"E:\Demo\Style Sheets\#3 Style Sheet.dot"
CommandBars("Paragraph Numbering").Visible = True

End Sub
 
S

Sammy

Forgot one thing, I also have the following macro which calls the style sheet
routine:

Sub opt1_Click()
Call NumOut1

End Sub
 
J

Jean-Guy Marcil

Sammy was telling us:
Sammy nous racontait que :
Forgot one thing, I also have the following macro which calls the
style sheet routine:

Sub opt1_Click()
Call NumOut1

End Sub

You need a Sub to call the form into being:
The complete code is as follows:

Sub CallForm

'Change this according to the name you gave to your userform
Dim myForm As MyUserFormName

Set myForm as New MyUserFormName

With myForm
'You could have other code here prior to showing the form
.Show
'You could do stuff with the user selection on the form after
'hiding it, but before unloading it from memory.
End With

Unload myForm

Set myFrom = Nothing

End Sub

--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
S

Sammy

THANKS A LOT!!!!!!!!!!

Jean-Guy Marcil said:
Sammy was telling us:
Sammy nous racontait que :


You need a Sub to call the form into being:
The complete code is as follows:

Sub CallForm

'Change this according to the name you gave to your userform
Dim myForm As MyUserFormName

Set myForm as New MyUserFormName

With myForm
'You could have other code here prior to showing the form
.Show
'You could do stuff with the user selection on the form after
'hiding it, but before unloading it from memory.
End With

Unload myForm

Set myFrom = Nothing

End Sub

--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top