F
Frank
I have tried to make a event handler to view a warning message, but before it
displayed, this system message pops up first: "<Filename> is already open.
Reopening will cause any changes you made to be discarded. Do you want to
reopen <filename>?"
How can I avoid the system message and only display my own message?
Regards
Frank Krogh
_________________________
Option Explicit
Sub ChangeDateFormat()
Dim strFileName As Variant
Dim wkbk As Workbook
Dim showMsg As String
strFileName = Application.GetOpenFilename("Report (*.xls),*.xls")
'Application.ScreenUpdating = False
If strFileName <> False Then
On Error GoTo ErrorHandler ' Enable error-handling routine.
Set wkbk = Workbooks.Open(Filename:=strFileName)
With wkbk.Worksheets(1)
' Do something
End With
End If
Exit Sub ' Exit to avoid handler.
ErrorHandler: ' Error-handling routine.
showMsg = MsgBox("File is already open. Please close and try again",
vbExclamation, "File already open")
Exit Sub
End Sub
displayed, this system message pops up first: "<Filename> is already open.
Reopening will cause any changes you made to be discarded. Do you want to
reopen <filename>?"
How can I avoid the system message and only display my own message?
Regards
Frank Krogh
_________________________
Option Explicit
Sub ChangeDateFormat()
Dim strFileName As Variant
Dim wkbk As Workbook
Dim showMsg As String
strFileName = Application.GetOpenFilename("Report (*.xls),*.xls")
'Application.ScreenUpdating = False
If strFileName <> False Then
On Error GoTo ErrorHandler ' Enable error-handling routine.
Set wkbk = Workbooks.Open(Filename:=strFileName)
With wkbk.Worksheets(1)
' Do something
End With
End If
Exit Sub ' Exit to avoid handler.
ErrorHandler: ' Error-handling routine.
showMsg = MsgBox("File is already open. Please close and try again",
vbExclamation, "File already open")
Exit Sub
End Sub