Cancel in Save As and Open

  • Thread starter Thread starter Con
  • Start date Start date
C

Con

Sub Macro5()
Hi
I have written a couple of simple macro's to SaveAs and
Open a file. The dialog box's opens fine and saves or
open OK. However when I use the cancel button in the
dialog box the file is either saved as false.xls or opened
as false.xls. Can you please advise what additional code
I need to include in the macro and where in the macro.
I've included the saveas macro below for reference. I
assume the code should include a statement such as Private
Sub Work_BeforeClose(Cancel as Boolean). However, as a
novice I don't know the full listing to include.

Thanks

Con

' Macro5 Macro
' Macro recorded 30/12/2003 by Fred
'
'
ChDir "C:\Spdsheets\Test"
Filt = "Excel Files(*.xls),*.xls"
ActiveWorkbook.SaveAs
Filename:=Application.GetSaveAsFilename _
(FileFilter:=Filt)


End Sub
 
Con,

strFilename = Application.GetSaveAsFilename(FileFilter:=Filt)
If strFilename <> "False" Then ActiveWorkbook.SaveAs strFilename

Rob
 
Just an added thought.

While implied by using a name like strFileName, the variable strFileName
should be explicitly dim'd as String

Dim strFileName as String
 
Back
Top