assigning a global variable in vba

lokeshsu

Board Regular
Joined
Mar 11, 2010
Messages
178
Hi all,


I am trying to assign a variable globally in vba, as i want to use that variable in different places in the vba code to get the path. i tried to do it using the option explicit and it was showing an error, below is code what i used.

Code:
Option Explicit
Public dbpath As String
Public dumppath As String
 dbpath = "c:\datadump.mdb"

Need help in fixing this issue

Thanks in advance
Lokesh Sundar
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
dbpath = "c:\datadump.mdb" <<< This belongs within (inside of) your Sub procedure.
 
Upvote 0
ya it should be in sub procedure but if i want to use a variable in different procedure how can we go about that
 
Upvote 0
to use a variable in different procedure :

1) A procedure within the Same Module, Place in the Declaration Section:
Dim dbpath As String
2) A Procedure in a Different Module of the Same Project (File) in the Declaration of
any Standard module:
Public dbpath As String
 
Upvote 0

Forum statistics

Threads
1,214,830
Messages
6,121,834
Members
449,051
Latest member
excelquestion515

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