View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Dave D-C[_3_] Dave D-C[_3_] is offline
external usenet poster
 
Posts: 176
Default Macro that waits, then resumes after window is closed

How do you 'stop' in VBA?
If you Exit Sub, then how do you get going again?
If you find better than this, please let me know:

Sub Main() ' (XL97/WIN98)
Dim WBName$, i%
Workbooks.Add
WBName = ActiveWorkbook.Name
MsgBox "Just opened " & Workbooks(WBName).Name
Do While XLWinStat(WBName) ' this is the 'wait' loop
' the for..next is to not hog the system
For i = 1 To 1000: DoEvents: Next i
Loop
MsgBox WBName & " is closed. Am proceeding ..."
End Sub

Function XLWinStat%(WBName$)
On Error GoTo XLWSerr
If Workbooks(WBName).Name = WBName Then
XLWinStat = 1: Exit Function
End If
Stop ' never gets here
XLWSerr: ' gets here when WBName is closed
End Function

Bob wrote:
You will need 2 macros, one that opens the workbook and stops, and then trap
the BeforeClose event of that workbook.


michael wrote
Does anyone know how to do the following:
I have a macro that does some things
including open up a workbook, then I need the macro to wait until this
workbook is closed while I edit some values, then proceed with the rest
of the macro.