View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Dave Peterson Dave Peterson is offline
external usenet poster
 
Posts: 35,218
Default Workbooks.Open suppresses MsgBox Displays when Macro is run

Remove the shift key from the hotkey assignment.

Holding down the shiftkey while you're opening a file tells excel not to run the
workbook_open event or the auto_open procedure. And it confuses excel so that
it never goes back to finish your code.

MichaelDavid wrote:

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"


--

Dave Peterson