Discussion:
Call a UserForm from an addin
(too old to reply)
Bill Longo
2009-01-29 04:53:00 UTC
Permalink
Hi,
I'm putting macros into a whole bunch of Word templates. Wanting to make a
userform global to a whole lot of other templates, I put the form
('frmLetter') into another WORD template called 'LetterDetails.dot' which
I've included as an addin.

However, I can't seem to call up 'frmLetter' from the bunch of templates.

The addin, 'LetterDetails.dot' is pointed to correctly. Infact I've set up a
test SUB in 'LetterDetails.dot' and have called that SUB from the bunch of
WORD templates and it works, so I know the addin is added in and
Application.Run("SUB name") wonderfully. I just can't access the userform.

I can get a reference from
ActiveDocument.VBProject.References("TemplateProject"), but I can't drill
into it to find 'frmLetter'.

I can iterate through VBA.UserForms displaying the names but 'frmLetter'
doesn't appear. I believe VBA.UserForms only shows loaded forms, so I guess
'frmLetter' isn't loaded yet.

I put a SUB in 'LetterDetails.dot' with the command 'frmLetter.Show()'. I
can get into the SUB to but it doesn't open up 'frmLetter'

I've tried VBA.UserForms.Add('frmLetter') but that didn't work.
Doug Robbins - Word MVP
2009-01-29 10:09:46 UTC
Permalink
Use the following command in each of your templates from which you want to
be able to call the userform:

Application.Run "LetterDetails.[ModuleName].[SubName]"

where you replace [SubName] with the name of the routine (Sub Name()) that
contains the commands to call the userform, and [ModuleName] with the name
of the module in LetterDetails.dot that contains the rountine [SubName].

For example, on my system I have an Add-in named DataCollector.dot that
contains a Module with the name of ShowDataItems and in that Module, there
is a user form with the name of frmDataCollector and a sub-routine

Sub ShowData()
'
Set myform = New frmDataCollector
' Other code deleted as it is not relevant to your question
myform.Show vbModeless
' Other code deleted as it is not relevant to your question
End Sub

Now, if in the Normal.dot template I create a macro

Sub Test()

Application.Run "DataCollector.ShowDataItems.ShowData"

End Sub

and run that macro, it displays the form frm DataCollector.
--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
Post by Bill Longo
Hi,
I'm putting macros into a whole bunch of Word templates. Wanting to make a
userform global to a whole lot of other templates, I put the form
('frmLetter') into another WORD template called 'LetterDetails.dot' which
I've included as an addin.
However, I can't seem to call up 'frmLetter' from the bunch of templates.
The addin, 'LetterDetails.dot' is pointed to correctly. Infact I've set up a
test SUB in 'LetterDetails.dot' and have called that SUB from the bunch of
WORD templates and it works, so I know the addin is added in and
Application.Run("SUB name") wonderfully. I just can't access the userform.
I can get a reference from
ActiveDocument.VBProject.References("TemplateProject"), but I can't drill
into it to find 'frmLetter'.
I can iterate through VBA.UserForms displaying the names but 'frmLetter'
doesn't appear. I believe VBA.UserForms only shows loaded forms, so I guess
'frmLetter' isn't loaded yet.
I put a SUB in 'LetterDetails.dot' with the command 'frmLetter.Show()'. I
can get into the SUB to but it doesn't open up 'frmLetter'
I've tried VBA.UserForms.Add('frmLetter') but that didn't work.
Bill Longo
2009-02-02 01:24:00 UTC
Permalink
Thanks Doug.

Thank you, thank you, thank you.

Your answer worked fine for me. Using the technique I'd tried of setting
up a Sub in the add-in to Show the form. I, however, hadn't set the form
first. I'd been trying to get that answer for a few hours over the internet
with no luck.

I've been a coder for a few years no and I always scrounge my answers off
the net. This is the first time I've ever had to join a group and post my
problem. It was a delight to have an answer my next working morning.

Thanks again.

Bill Longo
Post by Doug Robbins - Word MVP
Use the following command in each of your templates from which you want to
Application.Run "LetterDetails.[ModuleName].[SubName]"
where you replace [SubName] with the name of the routine (Sub Name()) that
contains the commands to call the userform, and [ModuleName] with the name
of the module in LetterDetails.dot that contains the rountine [SubName].
For example, on my system I have an Add-in named DataCollector.dot that
contains a Module with the name of ShowDataItems and in that Module, there
is a user form with the name of frmDataCollector and a sub-routine
Sub ShowData()
'
Set myform = New frmDataCollector
' Other code deleted as it is not relevant to your question
myform.Show vbModeless
' Other code deleted as it is not relevant to your question
End Sub
Now, if in the Normal.dot template I create a macro
Sub Test()
Application.Run "DataCollector.ShowDataItems.ShowData"
End Sub
and run that macro, it displays the form frm DataCollector.
--
Hope this helps.
Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.
Doug Robbins - Word MVP
Post by Bill Longo
Hi,
I'm putting macros into a whole bunch of Word templates. Wanting to make a
userform global to a whole lot of other templates, I put the form
('frmLetter') into another WORD template called 'LetterDetails.dot' which
I've included as an addin.
However, I can't seem to call up 'frmLetter' from the bunch of templates.
The addin, 'LetterDetails.dot' is pointed to correctly. Infact I've set up a
test SUB in 'LetterDetails.dot' and have called that SUB from the bunch of
WORD templates and it works, so I know the addin is added in and
Application.Run("SUB name") wonderfully. I just can't access the userform.
I can get a reference from
ActiveDocument.VBProject.References("TemplateProject"), but I can't drill
into it to find 'frmLetter'.
I can iterate through VBA.UserForms displaying the names but 'frmLetter'
doesn't appear. I believe VBA.UserForms only shows loaded forms, so I guess
'frmLetter' isn't loaded yet.
I put a SUB in 'LetterDetails.dot' with the command 'frmLetter.Show()'. I
can get into the SUB to but it doesn't open up 'frmLetter'
I've tried VBA.UserForms.Add('frmLetter') but that didn't work.
Doug Robbins - Word MVP
2009-02-02 02:17:45 UTC
Permalink
Glad to help.
--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
Post by Bill Longo
Thanks Doug.
Thank you, thank you, thank you.
Your answer worked fine for me. Using the technique I'd tried of setting
up a Sub in the add-in to Show the form. I, however, hadn't set the form
first. I'd been trying to get that answer for a few hours over the internet
with no luck.
I've been a coder for a few years no and I always scrounge my answers off
the net. This is the first time I've ever had to join a group and post my
problem. It was a delight to have an answer my next working morning.
Thanks again.
Bill Longo
Post by Doug Robbins - Word MVP
Use the following command in each of your templates from which you want to
Application.Run "LetterDetails.[ModuleName].[SubName]"
where you replace [SubName] with the name of the routine (Sub Name()) that
contains the commands to call the userform, and [ModuleName] with the name
of the module in LetterDetails.dot that contains the rountine [SubName].
For example, on my system I have an Add-in named DataCollector.dot that
contains a Module with the name of ShowDataItems and in that Module, there
is a user form with the name of frmDataCollector and a sub-routine
Sub ShowData()
'
Set myform = New frmDataCollector
' Other code deleted as it is not relevant to your question
myform.Show vbModeless
' Other code deleted as it is not relevant to your question
End Sub
Now, if in the Normal.dot template I create a macro
Sub Test()
Application.Run "DataCollector.ShowDataItems.ShowData"
End Sub
and run that macro, it displays the form frm DataCollector.
--
Hope this helps.
Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.
Doug Robbins - Word MVP
Post by Bill Longo
Hi,
I'm putting macros into a whole bunch of Word templates. Wanting to make a
userform global to a whole lot of other templates, I put the form
('frmLetter') into another WORD template called 'LetterDetails.dot' which
I've included as an addin.
However, I can't seem to call up 'frmLetter' from the bunch of templates.
The addin, 'LetterDetails.dot' is pointed to correctly. Infact I've set
up
a
test SUB in 'LetterDetails.dot' and have called that SUB from the bunch of
WORD templates and it works, so I know the addin is added in and
Application.Run("SUB name") wonderfully. I just can't access the userform.
I can get a reference from
ActiveDocument.VBProject.References("TemplateProject"), but I can't drill
into it to find 'frmLetter'.
I can iterate through VBA.UserForms displaying the names but 'frmLetter'
doesn't appear. I believe VBA.UserForms only shows loaded forms, so I guess
'frmLetter' isn't loaded yet.
I put a SUB in 'LetterDetails.dot' with the command 'frmLetter.Show()'. I
can get into the SUB to but it doesn't open up 'frmLetter'
I've tried VBA.UserForms.Add('frmLetter') but that didn't work.
Loading...