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

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
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,223,228
Messages
6,170,871
Members
452,363
Latest member
merico17

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