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

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.

Scott Huish

MrExcel MVP
Joined
Mar 17, 2004
Messages
19,961
Office Version
  1. 365
Platform
  1. Windows
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,191,609
Messages
5,987,651
Members
440,105
Latest member
thigarette

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
Top