Consulting

Results 1 to 5 of 5

Thread: Solved: Test for Existence of Toolbar

  1. #1
    VBAX Expert
    Joined
    Feb 2010
    Posts
    681
    Location

    Solved: Test for Existence of Toolbar

    How would I test for the existence of a dynamically created toolbar when a workbook is activated?

    I've tried the following but I'm receiving a Run-time Error (438) "Object doesn't support this property or method:"

    [VBA]
    If Application.CommandBars(myToolBar) = False Then
    Call CreateToolbar
    End If
    [/VBA]

    Thanks,

    Opv

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master xld's Avatar
    Joined
    Apr 2005
    Posts
    25,145
    Location
    Why not just delete in case?

    [vba]

    On Error Resume Next
    Application.CommandBars(myToolBar).Delete
    On Error Goto O

    Call CreateToolbar
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    VBAX Expert
    Joined
    Feb 2010
    Posts
    681
    Location
    [quote=xld]Why not just delete in case?

    I could, I guess. I was just wondering which would be the most streamlined procedure, so as to minimize the number of times the toolbar gets created and deleted. I currently have the toolbar being created when the workbook is initially opened, deleted anytime the workbook is deactivated (toggling between and among other workbooks) AND then recreated each time the workbook is activated.

    I'm running into an error when the workbook is initially opened. I am curious as to whether Excel is attempting to create the workbook twice (once because the workbook was opened and once because it was initially activated)? That's the only thing I can come up with as I don't get the error when I toggle between different workbooks. So, as a work-around I thought I'd just test for its existence so that when the workbook is initially opened, it won't try to create it twice and result in an error.

  4. #4
    Distinguished Lord of VBAX VBAX Grand Master xld's Avatar
    Joined
    Apr 2005
    Posts
    25,145
    Location
    I would just delete and create on open, and make non-visible on deactivation. This is a technique that I frequently use.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  5. #5
    VBAX Expert
    Joined
    Feb 2010
    Posts
    681
    Location
    Quote Originally Posted by xld
    I would just delete and create on open, and make non-visible on deactivation. This is a technique that I frequently use.
    Thanks. Sometimes I get so engrossed in trying to learn what I'm doing that I overlook the obvious. Simple solution. Thanks again.

    Opv

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •