View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Per Jessen Per Jessen is offline
external usenet poster
 
Posts: 1,533
Default Workbooks.Open suppresses MsgBox Displays when Macro is run

Hi Michael

Your code is working here in xl2000 and xl2007.

I opened a workbook which started a macro on open, and I did get the two
last messages when after focus was returned from the workbook_Open macro to
the initial macro.

BTW: I used a variable to hold the path and file name, rather than type it
twice risking a typo.

FileToOpen = "C:\Documents and Settings\Mike\IIR\Book1.xlsm"
Application.DisplayAlerts = True
If Dir(FileToOpen) < "" Then
' Book1.xlsm exists
MsgBox "BFROPEN"
Workbooks.Open (FileToOpen)
MsgBox "AFROPEN"
Else
MsgBox "PROBLEM"
End If
MsgBox "Finished!"

-----

HTH
Per

"MichaelDavid" skrev i meddelelsen
...
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"