Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 300
Default Calling workbooks with apostrophes in name?

In some of my spreadsheets I have one workbook run a macro in another open
workbook. The name of the workbooks are generally created by a macro, and
any apostrophes are removed. But sometimes the user puts them back in. And
it would be nicer to not remove them in the first place. An example line of
code that I'm using is:

Application.Run ("'" & TargetName & "'!HidePolicyPeriods")

How could it be written so apostrophes could be in TargetName?

Don <donwiss at panix.com.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 733
Default Calling workbooks with apostrophes in name?

"Don Wiss" wrote...
In some of my spreadsheets I have one workbook run a macro in another open
workbook. The name of the workbooks are generally created by a macro, and
any apostrophes are removed. But sometimes the user puts them back in. And
it would be nicer to not remove them in the first place. An example line of
code that I'm using is:

Application.Run ("'" & TargetName & "'!HidePolicyPeriods")

How could it be written so apostrophes could be in TargetName?


When in doubt, experiment. Create a dummy file with an embedded single quote
in the filename. Then open another file and write a formula that refers to a
cell in the first workbook. Once you've entered the formula, how does the
filename appear? On my system, the single quotes are doubled, so an external
reference to Sheet1!A1 in a file named foo'bar.xls appears as

='[foo''bar.xls]Sheet1'!A1

So try doubling the single quotes.


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 300
Default Calling workbooks with apostrophes in name?

On Fri, 16 Jul 2004 00:59:52 -0700, "Harlan Grove" wrote:

Don Wiss wrote...
In some of my spreadsheets I have one workbook run a macro in another open
workbook. The name of the workbooks are generally created by a macro, and
any apostrophes are removed. But sometimes the user puts them back in. And
it would be nicer to not remove them in the first place. An example line of
code that I'm using is:

Application.Run ("'" & TargetName & "'!HidePolicyPeriods")

How could it be written so apostrophes could be in TargetName?


When in doubt, experiment. Create a dummy file with an embedded single quote
in the filename. Then open another file and write a formula that refers to a
cell in the first workbook. Once you've entered the formula, how does the
filename appear? On my system, the single quotes are doubled, so an external
reference to Sheet1!A1 in a file named foo'bar.xls appears as

='[foo''bar.xls]Sheet1'!A1

So try doubling the single quotes.


The TargetName is under program control. So what I would have to do is to
write a function that doubled up any single apostrophe, that wasn't already
doubled. What I was hoping to find was an alternative construct that didn't
use apostrophes in the code.

Don <donwiss at panix.com.
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 733
Default Calling workbooks with apostrophes in name?

"Don Wiss" wrote...
....
The TargetName is under program control. So what I would have to do is to
write a function that doubled up any single apostrophe, that wasn't already
doubled. What I was hoping to find was an alternative construct that didn't
use apostrophes in the code.


As long as your filenames *could* include embedded single quotes, you're
going to *require* some means of doubling them when used as workbook names
to identify workbooks in Excel's object model. The only alternative involves
using persistent workbook-type object variables set when each file is
opened, but the precise approach to doing so depends on precisely how you're
opening these workbooks.


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 81
Default Calling workbooks with apostrophes in name?

An example line of code that I'm using is:

Application.Run ("'" & TargetName & "'!

HidePolicyPeriods")

How could it be written so apostrophes could be in
TargetName?


The TargetName is under program control. So what I would
have to do is to write a function that doubled up any
single apostrophe, that wasn't already doubled. What I
was hoping to find was an alternative construct that
didn't use apostrophes in the code.


Try:

TargetName = Application.Substitute(TargetName, "'", "''")
' ie single ' with two '
'or use Replace if sure only post xl97 version

TargetName = "'" & TargetName & "'" & "!"

Application.Run (TargetName & "tt")

The final embracing with apostrophes will not do any harm
if not required and also catch for other characters such
as spaces and dashes in the filename which also need
handling.

Regards,
Peter


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
Apostrophes in formula bar Joanne New Users to Excel 2 February 26th 08 07:32 PM
apostrophes teepee[_3_] Excel Discussion (Misc queries) 21 February 14th 08 01:05 AM
Apostrophes in Cell Megadrone Excel Worksheet Functions 4 February 22nd 07 01:51 PM
Apostrophes and Sorting [email protected] Excel Discussion (Misc queries) 3 October 23rd 06 02:01 PM
Dealing with hidden apostrophes... MavrikGandalf Excel Discussion (Misc queries) 1 July 26th 05 09:43 PM


All times are GMT +1. The time now is 03:30 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"