View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Peter T Peter T is offline
external usenet poster
 
Posts: 5,600
Default Single quote in filename causing problems

It's hard to understand what you have, what you want to do, and why.

Eg, is sSPEC_NAME something like this

Public sSPEC_NAME as String = "some_name"

if so, why not ensure the constant is included in the project before writing
the code

Why are you trying to evaluate the Name, do you expect it to refer to a
range, if so why not simply

set r = Range(sSPEC_NAME) ' etc

Regards,
Peter T


"geoff_ness" wrote in message
...
I would like to be able to evaluate the value of the named constant
sSPEC_NAME in the active workbook by using application.evaluate, as
follows:

Dim vTest as Variant

vTest = Application.Evaluate("'" & Application.ActiveWorkbook.Name &
"'!" & sSPEC_NAME)

This works fine, except where ActiveWorkbook.Name contains a single
quote, which causes the string being evaluated to become nonsense. Can
anyone suggest an alternative approach?

The most obvious to me would be

vTest =
Application.Evaluate(Application.ActiveWorkbook.Na mes(sSPEC_NAME).RefersTo)

but the issue then is that this will raise a runtime error where there
is no constant named sSPEC_NAME in the active workbook. Ideally I
would be to escape the single quote somehow in the first approach - is
there a way to do this?

TIA