View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Jake Marx[_3_] Jake Marx[_3_] is offline
external usenet poster
 
Posts: 860
Default Public Const to refer to a range name

Hi Tim,

TimT wrote:
Can this be done??
I'm trying to set this up and I'm having trouble.
Keep getting a compile error: Constant expression required.
________________________________________

Option Explicit

Public Const CDLoc = Range("CDFLoc").Value


No - a constant truly has to be static or constant. You could either use a
public variable or a public function that returns what you're looking for:

Public Function gsGetCDLoc() As String
gsGetCDLoc = Range("CDFLoc").Value
End Function

But at that point, you may as well write out the Range and the .Value
everywhere. I would suggest using a public constant for "CDFLoc" however -
that way, if your range name ever changes, you only have one place to change
it in your code.

--
Regards,

Jake Marx
www.longhead.com


[please keep replies in the newsgroup - email address unmonitored]