Computing.Net > Forums > Programming > Excel VBA Problem saving file

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Excel VBA Problem saving file

Reply to Message Icon

Name: dustybob
Date: September 19, 2006 at 13:38:13 Pacific
OS: Windows XP
CPU/Ram: intel p4 2.66GHz 512mb ra
Comment:

I'm trying to save an excel spreadsheet with the filename of K&N.csv but when I try and do this from within my macro, excel crashes when the workbook is closed. I can save the file and close the workbook manually with the name K&N.csv and excel doesn't crash. If I remove the ampere sign from the file name I can save the file as KN.csv from within the macro without any crash. Does anyone know how to save a file with excel vba and give it a filename that contains an ampere sign? Thanks any help is appreciated. Below is a copy of the code I used to save the file.

Private Sub
cmdUpdateWeb_Click()
On Error Resume Next
Application.DisplayAlerts = False
ActiveWorkbook.SaveAs Filename:= _
"C:\kn\K&N.csv", _
FileFormat:=xlCSV, CreateBackup:=False
Windows("K&N.CSV").Activate
ActiveWorkbook.Close False
Unload Me
End Sub




Sponsored Link
Ads by Google

Response Number 1
Name: StuartS
Date: September 19, 2006 at 19:26:17 Pacific
Reply:

I am afraid you wont be able to without some juggling. The ampersand has a special meaning in VBA and it doesn't like it anywhere it doesn't belong. It used a a type declaration character for a long integer.

You might try saving the file with a double ampersand and see if that works. It will appear as a single ampersand and you will have to retrieve it with a single ampersand.

Stuart


0

Response Number 2
Name: dustybob
Date: September 20, 2006 at 15:31:26 Pacific
Reply:

Ok I tried changing to a double ampersand and excel didn't crash after closing the file but the file that that was saved has the double ampersand in the filename and I need it to only have one ampersand in the name. Below is a copy of what I tried

Private Sub
cmdUpdateWeb_Click()
On Error Resume Next
Application.DisplayAlerts = False
ActiveWorkbook.SaveAs Filename:= _
"C:\kn\K&&N.csv", _
FileFormat:=xlCSV, CreateBackup:=False
Windows("K&N.CSV").Activate
ActiveWorkbook.Close False
Unload Me
End Sub



0

Response Number 3
Name: StuartS
Date: September 20, 2006 at 17:21:19 Pacific
Reply:

There is one otherthing you can try. Try saving the file as "K" + Chr(38) + "N.csv"

38 is the ASCII code for an & and it might fool VB to ingnoring it.

I have had problems with ampersands in variable names and database fields. VB just does not like it!

Stuart


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Excel VBA Problem saving file

Excel VBA syntax problem www.computing.net/answers/programming/excel-vba-syntax-problem/6298.html

Excel-VBA problem www.computing.net/answers/programming/excelvba-problem/3695.html

excel vba macro assistance www.computing.net/answers/programming/excel-vba-macro-assistance/10837.html