Hi Guys.
Just a quick question:
How to modify it into: continue marco if workbook.xls is open, or stop macro, if workbook.xls is not open.Windows("Workbook.xls").Activate
Sorry for the noobity level of the question
Hi Guys.
Just a quick question:
How to modify it into: continue marco if workbook.xls is open, or stop macro, if workbook.xls is not open.Windows("Workbook.xls").Activate
Sorry for the noobity level of the question
Try:
PS. Pana Łukasza oczywiście zapraszamy na polską wersję forum czyli z .pl na końcu. Ekipa z Wrocka jest dość licznie reprezentowana :-)HTML Code:
Best Regards,
Kaper
or
On Error Resume Next: Err.Clear Windows("Workbook.xls").Activate If Err Then MsgBox "Workbook.xls is not opened ", 64: Exit Sub On Error GoTo 0
And more basic question - May be instead of stopping macro it would be more appropriate to automaticaly open it (especially easy if we know the path).
Using my example (but could be also applied to one presented by nilem:
Sub test() Dim wbk As Workbook, cont As Boolean For Each wbk In Workbooks Debug.Print wbk.Name If LCase(wbk.Name) = "workbook.xls" Then cont = True Exit For End If Next wbk If cont Then Workbooks("Workbook.xls").Activate Else Workbooks.Open "Workbook.xls" 'will become active after opening. if needed info about path shall be added End If End Sub
Of course you don't have to remember "magic 64" - there is a constant vbInformation
Or I suppose, such situation shall trigger higher level of alert so vbCritical (16) will be more appropriate.
On Error Resume Next Err.Clear Windows("Workbook.xls").Activate If Err Then MsgBox "Workbook.xls is not open", vbCritical Err Clear Exit Sub end if On Error GoTo 0
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks