Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 15
Default Single quote in filename causing problems

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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Single quote in filename causing problems

This worked ok for me:

vTest = Application.Evaluate("'" _
& Replace(Application.ActiveWorkbook.Name, "'", "''") _
& "'!" & sSPEC_Name)



geoff_ness wrote:

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


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
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



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

Dave, you must be psychic <g
I didn't follow at all !

Regards,
Peter T

"Dave Peterson" wrote in message
...
This worked ok for me:

vTest = Application.Evaluate("'" _
& Replace(Application.ActiveWorkbook.Name, "'", "''") _
& "'!" & sSPEC_Name)



geoff_ness wrote:

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


--

Dave Peterson



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 15
Default Single quote in filename causing problems

Thanks Dave, works fine for me also :)


On Oct 30, 12:16*pm, Dave Peterson wrote:
This worked ok for me:

vTest = Application.Evaluate("'" _
* * * * * * & Replace(Application.ActiveWorkbook.Name, "'", "''") _
* * * * * * & "'!" & sSPEC_Name)



geoff_ness wrote:

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


--

Dave Peterson




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 15
Default Single quote in filename causing problems

Thanks Peter, sorry I didn't make myself clearer - I was under some
time pressure to get it sorted. The code constant sSPEC_NAME is one of
a number of such constants holding a string value, which are workbook-
level names(in the case of sSPEC_NAME, string constants rather than
ranges) in a group of workbooks related to a single application. The
vTest variable is used to let an event-handler procedure know which
part of the application the active workbook belongs to and which
procedures to call, and it can hold a string, boolean or range
depending on which of the code constants is being evaluated. You're
quite right though, if it was always a range your suggestion would
work.

On Oct 30, 12:24*pm, "Peter T" <peter_t@discussions wrote:
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


Reply
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
vlookup and using single quote Bishop Excel Worksheet Functions 2 April 3rd 09 06:02 PM
Single quote in sheet name ankur Excel Programming 3 September 28th 07 10:46 PM
Remove single quote Avadivelan TCS Excel Worksheet Functions 4 October 5th 06 03:48 PM
Leading single quote AA2e72E Excel Programming 2 May 13th 05 11:33 AM
Quote in filename causes problem with Application.Run Carolyn[_2_] Excel Programming 2 February 23rd 04 12:29 AM


All times are GMT +1. The time now is 04:44 AM.

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

About Us

"It's about Microsoft Excel"