View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming,microsoft.public.office.developer.vba
Jim Cone Jim Cone is offline
external usenet poster
 
Posts: 3,290
Default VBA and toolbars

Jonathan,

It appears from what you posted that the "appMenu" variable
data type is not declared. Also, "isthere" might be properly
declared as a CommandBar instead of as an Object.
I don't know whether that could be causing your problem,
but it is two straws on the camel's back.

Another approach, that I prefer is something like this...

'--------------------------------
On Error Resume Next
Application.CommandBars("SavvyC").Delete
On Error GoTo ErrorHandler
Set oCB = Application.CommandBars.Add(Name:=appMenu, temporary:=False)
'----------------------------------

Regards,
Jim Cone
San Francisco, USA



"Jonathan Rynd" wrote in message ...
Hi,
Our product (which we ship as an xla) is controlled via a toolbar, which
it creates on first run. In the module "ThisWorkbook" we have the
following code:
Private Sub Workbook_Open()
Dim oCB As CommandBar
Dim isthere As Object
appMenu = "SavvyC"
On Error GoTo create_toolbar
Set isthere = Application.CommandBars(appMenu)
Exit Sub
create_toolbar:
On Error GoTo 0
Set oCB = Application.CommandBars.Add(Name:=appMenu, temporary:=False)
[rest of code omitted]


On every machine we have tested it, the first time that the xla is
opened, since the SavvyC toolbar doesn't exist, there is (by design) an
error on the "Set isthere = " line, which causes the error handler (set
by the previous "On Error" statement) to jump to the create_toolbar
label. It then creates the toolbar.


However, we have one customer (Excel 2003, Windows XP SP1) for whom this
is not the case. When she opens the xla, instead of the On Error line
causing the flow of execution to resume at create_toolbar, the user gets
a run-time error, either Error -2147024809 (80070057) [which doesn't
make any sense] or Error 5 [which is a little more understandable but
still unexpected] with the error "Can't move focus to the control
because it is invisible, not enabled, or of a type that does not accept
the focus."


What does anybody make of this? Is there anything that we can tell the
enduser to do?


P.S. What's the difference between using Workbook_Open and Auto_Open?