Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi,
I want to store the name of the workbook in which the module/macro is actually there, in to a string variable. So that if I change the name of the workbook the macro will still run. I wrote the following, to try out whether it works Option Explicit Public Const s As String = ThisWorkbook.Name Sub try() MsgBox s End Sub Im getting a -- Compile error : constant expression required -- in the line -- Public Const s As String = ThisWorkbook.Name -- Bascially I have to use this workbook name in different subs within the same module , hence defined it as -- Public -- I read a recent post -- Dim Vs Public -- in which it was said that if am using a variable name only within the present module then we dont need to use Public but Dim would be sufficient. Why isn that working in the case of Constants. Like I defined the above as -- dim Const s As String = ThisWorkbook.Name -- and Im getting a -- compile error : expected identifier -- in the word "const". Where is my understanding going wrong? a) Why am I getting this error? b) Is the logic of using "Thisworkbook" correct? I mean would that ensure that -- s -- the string variable would have the name of the workbook in which the module is located. (Since, the above macro didnt work so I have no way of testing it, hence the query) Thanks a lot, Hari India |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
referring to previous worksheet in workbook | Excel Worksheet Functions | |||
Formula referring to a dynamic range in a different workbook | Excel Worksheet Functions | |||
Referring to external workbook in Data Validation | Excel Discussion (Misc queries) | |||
Referring to function in another workbook | Excel Worksheet Functions | |||
Identical menuitems referring to wrong workbook | Excel Programming |