Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Slash/backslash in directory causing error 1

Status
Not open for further replies.

davyre

Programmer
Oct 3, 2012
197
0
0
AU
Hi,
I have code like this:

Code:
Set objSheet = objExcel.Worksheets(1)
saveDir = "C:\Users\User\Desktop\" & UnitName & "-" & PONum & ".xlsx"
objBook.SaveAs (saveDir)

note that UnitName and PONum are string variables. This code is a piece of code from a button that will create a new Excel file with the name of 'UnitName-PONum'. So for example if UnitName is "Cutter" and PONum is "AAA505", then the Excel file created will be named Cutter-AAA505.xlsx
This is no problem with PONum such as "AAA505". But there are some cases that the PONum contains "/" , such as "Mail 17/06/13". If the PONum contains "/", it shows error saying Runtime Error 1004, MSOffice Excel Cannot access the file etc. etc. when the compiler goes to line [highlight #FCE94F]objBook.SaveAs (saveDir)[/highlight]

Is there any trick to overcome the problem with using "/"? Thank you
 
I'd use something like this:
Replace(PONum, "/", "-")

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
hey, that is a brilliant idea! Didnt think of it! Thanks!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top