PDA

View Full Version : Solved: GetSaveAs not actually saving?



pcollins
11-01-2007, 01:47 PM
Hi I have been trying to write some vba code that takes some data from various files, reformats it and then saves it as a *.csv file so that I can import it with a third party program. I have created this sub here and it seems to work fine except that it does not actually save the file, everything points to the file being saved, it even pops up a window saying the file was saved as XXXX.csv but the file is not there.

Anyone?


Sub CSV_Save()
YesNo = MsgBox("Do you wish to Save as a CSV File?", vbYesNo + vbCritical, "Caution")
Select Case YesNo
Case vbYes
fileSaveName = Application.GetSaveAsFilename( _
fileFilter:="Text Files (*.csv), *.csv")
If fileSaveName <> False Then
MsgBox "Save as " & fileSaveName
ActiveWorkbook.SaveAs
End If
'Pause= MsgBox("There is still time to save, "Caution")
Case vbNo
pauseforuser = MsgBox("You may still save the file manually", vbOKOnly, "Caution!")
End Select
End Sub

Bob Phillips
11-01-2007, 01:53 PM
Quote from help

Displays the standard Save As dialog box and gets a file name from the user without actually saving any files.

You have to save it yourself based upon the returned filename.

Norie
11-01-2007, 01:53 PM
GetSaveAsFileName does what it says on the tin, it gets the name to save the file by.

You have to write code yourself to do the save.

You've almost got it but you aren't actually using the name returned by GetSaveAsFileName.

ActiveWorkbook.SaveAs fileSaveName

pcollins
11-01-2007, 01:57 PM
Ahhh thanks, this is my first experience with VB/VBA. Its actually been a really long time since I have written any code at all (Fortran 77 in the early 90's)

My boss was wowed by what I did already, he didnt ask for it I just wanted to do something useful instead of hang out at the water cooler during my spare time at work.