LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 63
Default Referring to the base workbook in which the module is situated

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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
referring to previous worksheet in workbook Freida Excel Worksheet Functions 9 September 29th 09 09:33 PM
Formula referring to a dynamic range in a different workbook mr tom Excel Worksheet Functions 6 March 29th 07 08:56 AM
Referring to external workbook in Data Validation aposatsk Excel Discussion (Misc queries) 2 August 21st 06 04:24 PM
Referring to function in another workbook psp Excel Worksheet Functions 1 August 31st 05 10:32 PM
Identical menuitems referring to wrong workbook R Avery Excel Programming 5 January 30th 04 03:18 AM


All times are GMT +1. The time now is 11:01 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"