Cancel in Save As and Open

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
 
R

Rob van Gelder

Con,

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

Rob
 
T

Tom Ogilvy

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top