M
MichaelDavid
Greetings! This problem has me really stumped. I am running VBA in Excel
2007. My operating system is Windows XP Pro. (The problem also occurs when
the OS is Windows Vista.) The following VBA code runs perfectly when I run it
in the VBE via F5, displaying both the message "BFROPEN", the message
"AFROPEN", and the message "Finished!":
Application.DisplayAlerts = True
If Dir("C:\Documents and Settings\Mike\IIR\Book1.xlsm") <> "" Then
' Book1.xlsm exists
MsgBox "BFROPEN"
Workbooks.Open ("C:\Documents and Settings\Mike\IIR\Book1.xlsm")
MsgBox "AFROPEN"
Else
MsgBox "PROBLEM"
End If
MsgBox "Finished!"
But if I include the above code in a VBA macro, assign the macro a hot key,
and run it by typing the hot key, the message "BFROPEN" is displayed and file
Book1.xlsm is opened, but the message "AFROPEN" is not displayed. The message
"Finished" isn't displayed either. I suspect that there is something strange
about the behaviour of Workbooks.Open when it is an instruction in a macro
which is being executed. Any help or suggestions for further debugging will
be extremely appreciated. May you have a blessed day.
Sincerely,
Michael D Fitzpatrick
"EvangelMike"
2007. My operating system is Windows XP Pro. (The problem also occurs when
the OS is Windows Vista.) The following VBA code runs perfectly when I run it
in the VBE via F5, displaying both the message "BFROPEN", the message
"AFROPEN", and the message "Finished!":
Application.DisplayAlerts = True
If Dir("C:\Documents and Settings\Mike\IIR\Book1.xlsm") <> "" Then
' Book1.xlsm exists
MsgBox "BFROPEN"
Workbooks.Open ("C:\Documents and Settings\Mike\IIR\Book1.xlsm")
MsgBox "AFROPEN"
Else
MsgBox "PROBLEM"
End If
MsgBox "Finished!"
But if I include the above code in a VBA macro, assign the macro a hot key,
and run it by typing the hot key, the message "BFROPEN" is displayed and file
Book1.xlsm is opened, but the message "AFROPEN" is not displayed. The message
"Finished" isn't displayed either. I suspect that there is something strange
about the behaviour of Workbooks.Open when it is an instruction in a macro
which is being executed. Any help or suggestions for further debugging will
be extremely appreciated. May you have a blessed day.
Sincerely,
Michael D Fitzpatrick
"EvangelMike"