Workbook A(Sheet 1) and Workbook B(Sheet 2) are opened or not

Hi all,please help...

I want to write a VB-Excel macro , which will prompt a messgae box "Both W.B opened" if this macro finds Workbook A(Sheet 1) and Workbook B(Sheet 2) opened else msgbox "W.B NOT opened"

Can anyone write it for me???

Vishesh's picture

Not clear if Workbook A/B are

Not clear if Workbook A/B are actual name. However, here is the code that might do.

Sub MacroCheckWB()
If Application.Workbooks.Count >= 2 Then
MsgBox "Both W.B opened"
Else
MsgBox "W.B NOT opened"
End If
End Sub

Yes sir,Workbooks A and B are actual and their respective sheets

Hi Vishesh, thank you for replying..

Yes ,the names are actual , but i cannot find specific workbook and sheet name in the coding you wrote.

Basically my intention is to make a button in 3rd excel workbook on the click of which it il pop up a message box "W.B Opened" if both workbooks named A and B and their respective sheets named Sheet 1 and 2 , are opened.Else it will pop up msgbox "W.B not opened"

Regards
Ruth

Vishesh's picture

Check this out... Sub

Check this out...

Sub MacroCheckWB2()
Dim wbkA As Workbook
Dim wbkB As Workbook

On Error Resume Next
Set wbkA = Workbooks("A")
Set wbkB = Workbooks("B")
On Error GoTo 0

If Not wbkA Is Nothing And Not wbkB Is Nothing Then
If wbkA.ActiveSheet.Name = "Sheet1" And wbkB.ActiveSheet.Name = "Sheet2" Then
MsgBox "Both W.B opened"
Else
MsgBox "W.B NOT opened"
End If
Else
MsgBox "W.B NOT opened"
End If

Set wbkA = Nothing
Set wbkB = Nothing
End Sub