View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Peter T[_3_] Peter T[_3_] is offline
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