Public variable not seen by event module.

Roopher

Board Regular
Joined
Jul 8, 2008
Messages
73
Hi together!

Having searched the forums I go crazy now with the following unsolved situation:

I declare a public variable in a *standard module* to be used throughout the project. I can use that variable in that module.
---
Option Explicit
Public psWorkbookName As String <-------------This one here!


Private Sub AddCompanySheet_Click()
code here
---


But, when I like to use that same variable within the *workbook event module* (Workbook_Deactivate() or the like), it is not recognised: autocomplete does not work, 'Variable not defined' error when runnig/compiling.
---
Option Explicit


Private Sub Workbook_Deactivate()

psWorkbookName = ActiveWorkbook.Name

End Sub
---


What is the big flaw here? Declaring the public variable in the event module's declaration section gives the same error the other way around: the standard module's procedures won't recognise it! Anyone can help???
 
Last edited:

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
If you can't access a public variable then I would guess it is not in fact declared in a normal module, it is in a class module. (the fact that you showed what looks like an event procedure below it would tend to confirm that).
 
Upvote 0
Thank you so much, rorya!

You are right. Is works now! I had had the variable declared in the Sheet1 - module, not in a standard module, stupid me LOL...

Since I skipped the chapter with the class modules in the textbook because I did not get the concept, I never thought that I would have "class modules" in my workbook. Obviously, the modules in Sheet1, Sheet2 etc are all class modules! What a surprise!
 
Upvote 0

Forum statistics

Threads
1,214,834
Messages
6,121,871
Members
449,054
Latest member
juliecooper255

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