# Anyone know Visual Basic?

**URL:** <https://forums.speedlife.net/t/anyone-know-visual-basic/179302>\
**Category:** PittSpeed Off Topic\
**Created:** [January 6, 2006, 7:49am UTC](https://forums.speedlife.net/t/anyone-know-visual-basic/179302 "2006-01-06T07:49:03Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jeff95TA](https://yyz2.discourse-cdn.com/flex034/user_avatar/forums.speedlife.net/jeff95ta/32/5935_2.png) [@Jeff95TA](https://forums.speedlife.net/u/Jeff95TA)\
**Post date:** [January 6, 2006, 7:49am UTC](https://forums.speedlife.net/t/anyone-know-visual-basic/179302/1 "2006-01-06T07:49:03Z")

</div>

I have some VB code in Excel. Is there a way to tell how many workbooks are currently open, what their names are, and what worksheets are in them?

More specifically, I want to check to see if any of the open workbooks have a certain worksheet in them.

---

<div class="post-metadata">

**Author:** ![German\_with\_a\_Bowtie](https://yyz2.discourse-cdn.com/flex034/user_avatar/forums.speedlife.net/german_with_a_bowtie/32/5967_2.png) [@German\_with\_a\_Bowtie](https://forums.speedlife.net/u/German_with_a_Bowtie)\
**Post date:** [January 6, 2006, 7:52am UTC](https://forums.speedlife.net/t/anyone-know-visual-basic/179302/2 "2006-01-06T07:52:40Z")

</div>

Tools…Macro…Visual Basic Editor…Maximize…View…Project Explorer…View…Properties Window

---

<div class="post-metadata">

**Author:** ![Jenn](https://avatars.discourse-cdn.com/v4/letter/j/ba9def/32.png) [@Jenn](https://forums.speedlife.net/u/Jenn)\
**Post date:** [January 6, 2006, 7:54am UTC](https://forums.speedlife.net/t/anyone-know-visual-basic/179302/3 "2006-01-06T07:54:06Z")

</div>

Wow… Highschool is all coming back to me now…

I took VB, C++ in HS and have forgotten all of it!

---

<div class="post-metadata">

**Author:** ![Jeff95TA](https://yyz2.discourse-cdn.com/flex034/user_avatar/forums.speedlife.net/jeff95ta/32/5935_2.png) [@Jeff95TA](https://forums.speedlife.net/u/Jeff95TA)\
**Post date:** [January 6, 2006, 7:58am UTC](https://forums.speedlife.net/t/anyone-know-visual-basic/179302/4 "2006-01-06T07:58:08Z")

</div>

I need to write code that checks for the worksheet in all the open workbooks.

Reason is, I made some toolbars that are only used for my program. When you close the program I have it delete the toolbars. Problem is, if two copies of the program are open, and I delete the toolbar, then the 2nd one can’t use it. So I need to see if there are two copies open, and only delete the toolbars when BOTH are closed.

---

<div class="post-metadata">

**Author:** ![MONTE\_SS](https://avatars.discourse-cdn.com/v4/letter/m/8797f3/32.png) [@MONTE\_SS](https://forums.speedlife.net/u/MONTE_SS)\
**Post date:** [January 6, 2006, 8:12am UTC](https://forums.speedlife.net/t/anyone-know-visual-basic/179302/5 "2006-01-06T08:12:44Z")

</div>

Are you running from Excel, or VB application?

---

<div class="post-metadata">

**Author:** ![Jeff95TA](https://yyz2.discourse-cdn.com/flex034/user_avatar/forums.speedlife.net/jeff95ta/32/5935_2.png) [@Jeff95TA](https://forums.speedlife.net/u/Jeff95TA)\
**Post date:** [January 6, 2006, 8:15am UTC](https://forums.speedlife.net/t/anyone-know-visual-basic/179302/6 "2006-01-06T08:15:58Z")

</div>

> [@montekass](#):
>
> Are you running from Excel, or VB application?

Running from Excel

---

<div class="post-metadata">

**Author:** ![German\_with\_a\_Bowtie](https://yyz2.discourse-cdn.com/flex034/user_avatar/forums.speedlife.net/german_with_a_bowtie/32/5967_2.png) [@German\_with\_a\_Bowtie](https://forums.speedlife.net/u/German_with_a_Bowtie)\
**Post date:** [January 6, 2006, 8:17am UTC](https://forums.speedlife.net/t/anyone-know-visual-basic/179302/7 "2006-01-06T08:17:12Z")

</div>

Just a suggestion, rather than going this route, you could add some code to add some text to your toolbar name that would correspond to the number of open programs. ex(TOOLBARNAME. for 1 open program, TOOLBARNAME… for two open programs) Then just do some IF…THEN when closing to adjust the name and close the toolbar if needed. OR, I know you can use the Window() function to move about and open/close worksheets, If you through in an ON LOCAL ERROR routine, you could trap out any non occurrence in the active workbook. I’m not sure how to determine the names of other open workbooks though, so I can’t help with that.

---

<div class="post-metadata">

**Author:** ![eurodad](https://yyz2.discourse-cdn.com/flex034/user_avatar/forums.speedlife.net/eurodad/32/5988_2.png) [@eurodad](https://forums.speedlife.net/u/eurodad)\
**Post date:** [January 6, 2006, 8:18am UTC](https://forums.speedlife.net/t/anyone-know-visual-basic/179302/8 "2006-01-06T08:18:33Z")

</div>

nerds

---

<div class="post-metadata">

**Author:** ![Jeff95TA](https://yyz2.discourse-cdn.com/flex034/user_avatar/forums.speedlife.net/jeff95ta/32/5935_2.png) [@Jeff95TA](https://forums.speedlife.net/u/Jeff95TA)\
**Post date:** [January 6, 2006, 8:24am UTC](https://forums.speedlife.net/t/anyone-know-visual-basic/179302/9 "2006-01-06T08:24:09Z")

</div>

> [@eurodad](#):
>
> nerds

:finger: This is paying for my short block!

---

<div class="post-metadata">

**Author:** ![newchic](https://yyz2.discourse-cdn.com/flex034/user_avatar/forums.speedlife.net/newchic/32/5989_2.png) [@newchic](https://forums.speedlife.net/u/newchic)\
**Post date:** [January 6, 2006, 9:20am UTC](https://forums.speedlife.net/t/anyone-know-visual-basic/179302/10 "2006-01-06T09:20:33Z")

</div>

> [@eurodad](#):
>
> nerds

Do you even know what VB is? :stick:

---

<div class="post-metadata">

**Author:** ![MONTE\_SS](https://avatars.discourse-cdn.com/v4/letter/m/8797f3/32.png) [@MONTE\_SS](https://forums.speedlife.net/u/MONTE_SS)\
**Post date:** [January 6, 2006, 9:30am UTC](https://forums.speedlife.net/t/anyone-know-visual-basic/179302/11 "2006-01-06T09:30:58Z")

</div>

> [@GeneralG](#):
>
> Just a suggestion, rather than going this route, you could add some code to add some text to your toolbar name that would correspond to the number of open programs. ex(TOOLBARNAME. for 1 open program, TOOLBARNAME… for two open programs) Then just do some IF…THEN when closing to adjust the name and close the toolbar if needed. OR, I know you can use the Window() function to move about and open/close worksheets, If you through in an ON LOCAL ERROR routine, you could trap out any non occurrence in the active workbook. I’m not sure how to determine the names of other open workbooks though, so I can’t help with that.

Thats where I was going, to determine the names couldn’t you have very simple Do/While loop “text”?

---

<div class="post-metadata">

**Author:** ![Pewter](https://yyz2.discourse-cdn.com/flex034/user_avatar/forums.speedlife.net/pewter/32/5936_2.png) [@Pewter](https://forums.speedlife.net/u/Pewter)\
**Post date:** [January 6, 2006, 9:45am UTC](https://forums.speedlife.net/t/anyone-know-visual-basic/179302/12 "2006-01-06T09:45:53Z")

</div>

i met him once

---

<div class="post-metadata">

**Author:** ![81Boo](https://avatars.discourse-cdn.com/v4/letter/8/ac8455/32.png) [@81Boo](https://forums.speedlife.net/u/81Boo)\
**Post date:** [January 6, 2006, 10:42am UTC](https://forums.speedlife.net/t/anyone-know-visual-basic/179302/13 "2006-01-06T10:42:20Z")

</div>

> [@newchic](#):
>
> Do you even know what VB is? :stick:

verbatim?

---

<div class="post-metadata">

**Author:** ![Old\_Dirty\_Georg](https://avatars.discourse-cdn.com/v4/letter/o/7ab992/32.png) [@Old\_Dirty\_Georg](https://forums.speedlife.net/u/Old_Dirty_Georg)\
**Post date:** [January 6, 2006, 12:26pm UTC](https://forums.speedlife.net/t/anyone-know-visual-basic/179302/14 "2006-01-06T12:26:25Z")

</div>

> [@PewterSS](#):
>
> i met him once

That was not VB, that was VD (venereal disease  
). 😃 :love:

---

<div class="post-metadata">

**Author:** ![Pewter](https://yyz2.discourse-cdn.com/flex034/user_avatar/forums.speedlife.net/pewter/32/5936_2.png) [@Pewter](https://forums.speedlife.net/u/Pewter)\
**Post date:** [January 6, 2006, 12:36pm UTC](https://forums.speedlife.net/t/anyone-know-visual-basic/179302/15 "2006-01-06T12:36:31Z")

</div>

> [@Old Dirty Georg](#):
>
> That was not VB, that was VD (venereal disease  
> ). 😃 :love:

ya,thanks for giving it to me! :greddy:

---

<div class="post-metadata">

**Author:** ![Old\_Dirty\_Georg](https://avatars.discourse-cdn.com/v4/letter/o/7ab992/32.png) [@Old\_Dirty\_Georg](https://forums.speedlife.net/u/Old_Dirty_Georg)\
**Post date:** [January 6, 2006, 12:42pm UTC](https://forums.speedlife.net/t/anyone-know-visual-basic/179302/16 "2006-01-06T12:42:10Z")

</div>

:gaysex:

It’s the gift that keeps on giving…

---

<div class="post-metadata">

**Author:** ![imported\_weaves](https://avatars.discourse-cdn.com/v4/letter/i/bc8723/32.png) [@imported\_weaves](https://forums.speedlife.net/u/imported_weaves)\
**Post date:** [January 6, 2006, 12:48pm UTC](https://forums.speedlife.net/t/anyone-know-visual-basic/179302/17 "2006-01-06T12:48:51Z")

</div>

Try this:  
Edit…just re read what you want, try this one.

```auto

    numopen = Workbooks.Count
    For i = 1 To numopen
        If Workbooks.Item(i).Name = "WHATEVER" Then
            numopenws = Workbooks.Item(i).Worksheets.Count
            For j = 1 To numopenws
                If Workbooks.Item(i).Worksheets.Item(j).Name = "WHATEVER" Then
                 '
                 'YOUR COMMANDS HERE
                 '
                End If
            Next j
        End If
    Next i

```

---

<div class="post-metadata">

**Author:** ![MONTE\_SS](https://avatars.discourse-cdn.com/v4/letter/m/8797f3/32.png) [@MONTE\_SS](https://forums.speedlife.net/u/MONTE_SS)\
**Post date:** [January 6, 2006, 1:10pm UTC](https://forums.speedlife.net/t/anyone-know-visual-basic/179302/18 "2006-01-06T13:10:07Z")

</div>

Ya but will that continue to other workbooks, or just stop once that is found?

---

<div class="post-metadata">

**Author:** ![imported\_weaves](https://avatars.discourse-cdn.com/v4/letter/i/bc8723/32.png) [@imported\_weaves](https://forums.speedlife.net/u/imported_weaves)\
**Post date:** [January 6, 2006, 1:19pm UTC](https://forums.speedlife.net/t/anyone-know-visual-basic/179302/19 "2006-01-06T13:19:30Z")

</div>

Should keep going, it’s a for loop. If he wants it to stop he can put in a Exit Function or Exit Sub depending on how he’s doing it

---

<div class="post-metadata">

**Author:** ![Jeff95TA](https://yyz2.discourse-cdn.com/flex034/user_avatar/forums.speedlife.net/jeff95ta/32/5935_2.png) [@Jeff95TA](https://forums.speedlife.net/u/Jeff95TA)\
**Post date:** [January 6, 2006, 1:59pm UTC](https://forums.speedlife.net/t/anyone-know-visual-basic/179302/20 "2006-01-06T13:59:03Z")

</div>

I’ll try this on Monday. I was on the right track but I couldn’t get the Workbooks.Count working.

Thanks for the help!

[Next page](https://forums.speedlife.net/t/anyone-know-visual-basic/179302.md?page=2)
