Hyphen in worksheet name when

gdesreu

Active Member
Joined
Jul 30, 2012
Messages
318
I run a series of queries in access and then export them to an excel file and name the worksheet. I have one worksheet that must contain a hyphen but when it exports it to excel the worksheet name has an underscore inserted instead of the name I entered. Does anyone know how to keep the hyphen from being converted to an underscore.

Offending code:
VBA Code:
If DCount("sampname", "qry_test") Then
    cnt = cnt + 1
    DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, "qry_test", "C:\Projects\Error Report\Report_working.xls", True, "NJ-AAA_Flag_Check"
End If

"NJ-AAA_Flag_Check" is converted to "NJ_AAA_Flag_Check"
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
Not sure, because running into this over the years I would never use special characters or spaces in the name of anything. Not drive folders, not file names, not sheets - not anything that could potentially be involved in vba or sql. You could try escaping it (--) or see if there is an escape character in vba. Or you could try the ASCII value for - (decimal 44). See
 
Upvote 0
Thanks, unfortunately the more I tell people not to use special characters in things like filepaths and sheetnames, the more they do it. In this particular case its not an option, the sheet must be named that way per the client.
 
Upvote 0
Aside from that already suggested, here's an afterthought: try "NJ" & "-" & "AAA_Flag_Check"
Using suggested ASCII might look like "NJ" & Chr(45) & "AAA_Flag_Check"
 
Upvote 0
Can you tell us more about "one worksheet that must contain a hyphen." Perhaps change/redesign the logic that demands this constraint.

Brute force maybe replace the - with say "WZW", perform your logic, export then Replace WZW with "-".
 
Upvote 0

Forum statistics

Threads
1,224,586
Messages
6,179,713
Members
452,939
Latest member
WCrawford

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top