Passing variables to another procedure

K

Kerri

Hi all,

I have created a macro in Word 2003. How can I make one macro have
three different results. In other words. I can copy the macro three
times and give it different names so the users can have a choice of
choose w/o date, w/date or w/date and time. Originally I created user
form so they could choose one of the three options and then passed
that variable result in to a case select statement in my macro. The
powers that be don't want the extra step of clicking in the user
form. They want to choose from the menu one of the three choices and
have it run the macro.

I was trying to avoid having the macro created three times...incase I
need to make a change and update it later. So, what I thought of was
to have a macro that calls the main macro, and use a variable that
will be pulled down in to the main macro. I hope this makes sence?
Here is what I tired with no luck.
Kerri

'This would be the macro that would be in the menu
Sub FtrInfoNOdate()
'I read that if you put the variable in the "(strDateOption )" that
you can call it in other macros, but then it doesn't know what macro
to run...so obviously I'm interpreting it wrong Dim
Dim strDateOption As String
strDateOption = "No Date"
MainMacro
End Sub

'This would be the macro that would be in the menu
Sub FtrInfoYESdate()
'I read that if you put the variable in the "()" that you can call
it in other macros
Dim strDateOption As String
strDateOption = "Yes insert Date"
MainMacro
End Sub

'This would be the macro that would be in the menu
Sub FtrInfoYESdateTime()
'I read that if you put the variable in the "()" that you can call
it in other macros
Dim strDateOption As String
strDateOption = "Yes insert Date & Time"
MainMacro
End Sub

'==============
Sub MainMacro()
Dim strDateOption As String
Select Case strDateOption

Case "No Date"
'using msgbox as example to see its working...I'll replace with
actual code later
MsgBox "Do not insert Date"

Case "Yes Date"
MsgBox "Yes insert Date"

Case "Yes Date & Time"
MsgBox "Yes insert Date & Time"

End Select
'do other things here...
End Sub
 
J

Jean-Guy Marcil

Kerri was telling us:
Kerri nous racontait que :
Hi all,

I have created a macro in Word 2003. How can I make one macro have
three different results. In other words. I can copy the macro three
times and give it different names so the users can have a choice of
choose w/o date, w/date or w/date and time. Originally I created user
form so they could choose one of the three options and then passed
that variable result in to a case select statement in my macro. The
powers that be don't want the extra step of clicking in the user
form. They want to choose from the menu one of the three choices and
have it run the macro.
I was trying to avoid having the macro created three times...incase I
need to make a change and update it later. So, what I thought of was
to have a macro that calls the main macro, and use a variable that
will be pulled down in to the main macro. I hope this makes sence?
Here is what I tired with no luck.
Kerri

'This would be the macro that would be in the menu
Sub FtrInfoNOdate()
'I read that if you put the variable in the "(strDateOption )" that
you can call it in other macros, but then it doesn't know what macro
to run...so obviously I'm interpreting it wrong Dim
Dim strDateOption As String
strDateOption = "No Date"
MainMacro
End Sub

'This would be the macro that would be in the menu
Sub FtrInfoYESdate()
'I read that if you put the variable in the "()" that you can call
it in other macros
Dim strDateOption As String
strDateOption = "Yes insert Date"
MainMacro
End Sub

'This would be the macro that would be in the menu
Sub FtrInfoYESdateTime()
'I read that if you put the variable in the "()" that you can call
it in other macros
Dim strDateOption As String
strDateOption = "Yes insert Date & Time"
MainMacro
End Sub

'==============
Sub MainMacro()
Dim strDateOption As String
Select Case strDateOption

Case "No Date"
'using msgbox as example to see its working...I'll replace with
actual code later
MsgBox "Do not insert Date"

Case "Yes Date"
MsgBox "Yes insert Date"

Case "Yes Date & Time"
MsgBox "Yes insert Date & Time"

End Select
'do other things here...
End Sub

Normally, what we do is something like:

'_______________________________________
Sub CalledMacro1()
Dim strDateOption As String

strDateOption = "No Date"
MainMacro strDateOption

End Sub
'_______________________________________

'_______________________________________
Sub CalledMacro2()

Dim strDateOption As String

strDateOption = "Yes Date"
MainMacro strDateOption


End Sub
'_______________________________________

'_______________________________________
Sub MainMacro(ByVal strOption As String)

Select Case strOption

Case "No Date"
MsgBox "Do not insert Date"
Case "Yes Date"
MsgBox "Yes insert Date"
Case Else
MsgBox "Yes insert Date & Time"
End Select

'do other things here...

End Sub
'_______________________________________

You could replace the three called macros by one. If you have a menu on a
toolbar, have each item in the menu call the same macro (i.e. Insert the
macro three times on the menu). Then change each menu item's caption to
something appropriate, like "Date", Date & Time" and "No Date". Finally use
only two macros as follows:

'_______________________________________
Sub CalledMacro()

'ActionControl is the button that was just clicked on...
MainMacro Application.CommandBars.ActionControl.Caption

End Sub
'_______________________________________

'_______________________________________
Sub MainMacro(ByRef strOption As String)

Select Case strOption
Case "Date"
MsgBox "Yes insert Date"
Case "Date and Time"
MsgBox "Yes insert Date and Time"
Case Else
MsgBox "Do not insert Date"
End Select

'do other things here...

End Sub
'_______________________________________
--

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

Kerri

Jean-Guy,

Very cool!
I was close, but not close enough. This is exciting...I'm going to
try the control option. It seems to be best choice with least
effort. Thank you so much for taking the time to help me! I
appreciate it.

Kerri
 

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