Make dictionary object globally available

mwl707

New Member
Joined
Jun 5, 2024
Messages
6
Office Version
  1. 2021
Platform
  1. Windows
Im trying to call a function and reference dictionary data from the sub. I just cant seem to declare the vrnHistory dictionary as a global resource. Ive stripped to the code down but the basics are below. I want to achive the MsgBox displaying the string is A1.
I know I need to dim vrnHistory as public but i cant make it work.
Any help much appreciated !

Public Sub GlobalTest()

Set vrnHistory = CreateObject("Scripting.Dictionary")

vrnHistory.Add "A1", "This is dictionary Data for global share"

FN_GlobalTest

End Sub


Public Function FN_GlobalTest()

MsgBox "Within Function called from SUB " & vrnHistory("A1")

End Function
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
You'll need to declare vrnHistory at the very top of your module, before any procedure or function.

If you want the variable available only within the module itself, declare the variable with the Dim keyword...

VBA Code:
Dim vrnHistory As Object

If you want the variable available to all regular modules within the project, declare the variable using the Public keyword...

VBA Code:
Public vrnHistory As Object

Hope this helps!
 
Upvote 0
You'll need to declare vrnHistory at the very top of your module, before any procedure or function.

If you want the variable available only within the module itself, declare the variable with the Dim keyword...

VBA Code:
Dim vrnHistory As Object

If you want the variable available to all regular modules within the project, declare the variable using the Public keyword...

VBA Code:
Public vrnHistory As Object

Hope this helps!
Thats a great help, thanks for taking the time to reply!
 
Upvote 0

Forum statistics

Threads
1,223,897
Messages
6,175,271
Members
452,628
Latest member
dd2

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