Cancel Message

stephen81

Registered User.
Local time
Today, 08:07
Joined
Nov 27, 2002
Messages
198
I have some code in Excel that allows the user to open a .lis file, it then creates a new workbook and formats the information how I want it and then gives the user the option of where to save the new file.

I have a message box which is supposed to pop up if cancel is pressed on either the open or save dialogue boxes however, it seems to pop up after the Save dialogue box even if save is selected. It still saves the file so it's not crucial just a bit annoying. Can anyone see what is wrong with my code?

Sub Workbook_Open()

On Error Resume Next

FullFileName = Application.GetOpenFilename("List Files (*.lis), *.lis", _
1, "Select List File", , False)

If FullFileName = False Then GoTo Cancel

Dim wrk As Workbook
Dim wrk2 As Workbook
Application.ScreenUpdating = False
'Application.Visible = False
Workbooks.OpenText FullFileName, Origin:=xlWindows, _
StartRow:=1, DataType:=xlFixedWidth, FieldInfo:=Array(Array(0, 9), Array(1, _
2), Array(12, 2), Array(16, 2), Array(42, 4), Array(54, 4), Array(66, 1))


VARIOUS IN HERE TO FORMAT WORKBOOK AS REQUIRED


FullFileName = Application.GetSaveAsFilename("filename.xls", _
"Excel files (*.xls),*.xls", 1, "Where would you like to save converted file?")

On Error Resume Next

If FullFileName = False Then GoTo Cancel


ActiveWorkbook.SaveAs FullFileName, FileFormat:=xlNormal, _
Password:="", WriteResPassword:="", ReadOnlyRecommended:=False, _
CreateBackup:=False

Application.Quit

Cancel:
MsgBox "The Cancel button was selected."
Application.Visible = True
Application.ScreenUpdating = True

End Sub


Any questions, please ask. Thanks in advance for your help.
 

Users who are viewing this thread

Back
Top Bottom