PDA

View Full Version : Solved: Test for Existence of Toolbar



Opv
06-22-2010, 08:18 AM
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:"


If Application.CommandBars(myToolBar) = False Then
Call CreateToolbar
End If


Thanks,

Opv

Bob Phillips
06-22-2010, 08:28 AM
Why not just delete in case?



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

Call CreateToolbar

Opv
06-22-2010, 08:42 AM
[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.

Bob Phillips
06-22-2010, 08:48 AM
I would just delete and create on open, and make non-visible on deactivation. This is a technique that I frequently use.

Opv
06-22-2010, 09:15 AM
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