Is it possible to define variables for one Macro in a seperate Macro?

YeshyTiger

New Member
Joined
Oct 21, 2008
Messages
23
Hello,
I'm trying to define a set of 3 variables in Macro A using Macro B. This is being done in order to bypass redefining those variables each time I run Macro A. The variables being defined are folders for save locations. Any tips/starters? Thank you in advance
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
If they will stay the same, you could define them as constants:

Code:
Public Const Folder1 As String = "C:\test"
Public Const Folder2 As String = "C:\test2"
Public Const Folder3 As String = "C:\test3"

Sub test()
MsgBox Folder1
MsgBox Folder2
MsgBox Folder3
End Sub

or you could use Global variables:

Code:
Public Folder1 As String
Public Folder2 As String
Public Folder3 As String

Sub test()
MsgBox Folder1
MsgBox Folder2
MsgBox Folder3
End Sub

Sub MacroB()
Folder1 = "C:\test"
Folder2 = "C:\test2"
Folder3 = "C:\test3"
Call test
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,006
Messages
6,122,666
Members
449,091
Latest member
peppernaut

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top