Find an Open Excel And Call Subs

AnnAnn

New Member
Joined
Mar 26, 2024
Messages
36
Office Version
  1. 2016
Hello,
I have searched but haven't found what I am looking for; appreciate any help given.
I need to create a macro in a workbook that will find an Excel workbook that is already open and where cell A1 contains the word 'Network' on the 2nde visible sheet. Once it finds that Excel, it needs to run other Subs, which I know how to create. I am stuck on how to find the open Excel workbook with the criteria mentioned.
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
Not sure what you mean by second visible sheet. It could be 2nd tab from the left with one or more hidden to the left of that. It might also mean the sheet that has an index value of 2. Anyway, this worked for me in my testing, but I did not worry if the sheet is "second" or not. I would think it doesn't matter if it is the only sheet with the word "Network" in a cell:
VBA Code:
Sub getWBname()
Dim wb As Workbook
Dim sht As Worksheet

For Each wb In Application.Workbooks
    For Each sht In wb.Worksheets
        If sht.Visible Then
            If sht.Range("B1") = "Network" Then MsgBox wb.Name
        End If
    Next
Next

End Sub
I used B1 rather than alter my data.
 
Upvote 0
A reminder:

Cross-posting (posting the same question in more than one forum) is not against our rules, but the method of doing so is covered by #13 of the Forum Rules.

Be sure to follow & read the link at the end of the rule too!

Cross posted at:

There is no need to repeat the link(s) provided above but if you have posted the question at other places, please provide links to those as well.

If you do cross-post in the future and also provide links, then there shouldn’t be a problem.
 
Upvote 0
Not sure what you mean by second visible sheet. It could be 2nd tab from the left with one or more hidden to the left of that. It might also mean the sheet that has an index value of 2. Anyway, this worked for me in my testing, but I did not worry if the sheet is "second" or not. I would think it doesn't matter if it is the only sheet with the word "Network" in a cell:
VBA Code:
Sub getWBname()
Dim wb As Workbook
Dim sht As Worksheet

For Each wb In Application.Workbooks
    For Each sht In wb.Worksheets
        If sht.Visible Then
            If sht.Range("B1") = "Network" Then MsgBox wb.Name
        End If
    Next
Next

End Sub
I used B1 rather than alter my data.
Thanks, Micron. I received the following error, Compile Error: Expected variable or procedure, not module.
 
Upvote 0
A reminder:

Cross-posting (posting the same question in more than one forum) is not against our rules, but the method of doing so is covered by #13 of the Forum Rules.

Be sure to follow & read the link at the end of the rule too!

Cross posted at:

There is no need to repeat the link(s) provided above but if you have posted the question at other places, please provide links to those as well.

If you do cross-post in the future and also provide links, then there shouldn’t be a problem.
Ahh, forgot, thank you for the reminder, RoryA.
 
Upvote 0
Sorry, I'm out. I don't have time to follow 2 or more threads for the same issue, especially when neither is linked to.
 
Upvote 0
Sorry, I'm out. I don't have time to follow 2 or more threads for the same issue, especially when neither is linked to.
Ok. Not sure what you mean by 'especially when neither is linked to'. To what?
 
Upvote 0
Ok. Not sure what you mean by 'especially when neither is linked to'. To what?
Cross posting without linking as RoryA said. Not done in either thread when I looked.
 
Upvote 0

Forum statistics

Threads
1,223,909
Messages
6,175,310
Members
452,634
Latest member
cpostell

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top