VBA: Custom Toolbar help

H

hedonists

I built a custom tool bar for my applicatoin. It works ok on PC Excel. But I
got an error message on a Mac Excel:
Run-time error '-2147483640(-7FFFFFF8)':
Method 'FaceId' of object 'CommandBarButton' failed
If I comment out the .FaceId = 642
Then the error message becomes
Method 'OnAction' of object 'CommandBarButton' failed


The original code in VBA look like this:
...............
Set NewBtn1 = Application.CommandBars("Lenses Design").Controls.Add(Type:=
msoControlButton)
With NewBtn1
.FaceId = 642
.OnAction = "ThisWorkbook.LensDesign"
.Caption = "Design"
.TooltipText = "Design aerodynamic lenses"
.Style = 3
End With
...............

Does anybody know how to solve this problem?
Thanks a lot.
 
J

JE McGimpsey

hedonists said:
I built a custom tool bar for my applicatoin. It works ok on PC Excel. But I
got an error message on a Mac Excel:
Run-time error '-2147483640(-7FFFFFF8)':
Method 'FaceId' of object 'CommandBarButton' failed
If I comment out the .FaceId = 642
Then the error message becomes
Method 'OnAction' of object 'CommandBarButton' failed


The original code in VBA look like this:
..............
Set NewBtn1 = Application.CommandBars("Lenses Design").Controls.Add(Type:=
msoControlButton)
With NewBtn1
.FaceId = 642
.OnAction = "ThisWorkbook.LensDesign"
.Caption = "Design"
.TooltipText = "Design aerodynamic lenses"
.Style = 3
End With
..............

Does anybody know how to solve this problem?
Thanks a lot.

Hmm... works fine for me in XL04.

Do you create the CB using code? Do you declare NewBtn1's data type? If
so, as what?

Note that ThisWorkbook.LensDesign has to be a public Sub (and I
generally recommend moving it to a regular code module rather than the
Workbook class module, which I save for event macros only).
 
A

Anands

"hedonists" ने लिखा:
I built a custom tool bar for my applicatoin. It works ok on PC Excel. But I
got an error message on a Mac Excel:
Run-time error '-2147483640(-7FFFFFF8)':
Method 'FaceId' of object 'CommandBarButton' failed
If I comment out the .FaceId = 642
Then the error message becomes
Method 'OnAction' of object 'CommandBarButton' failed


The original code in VBA look like this:
..............
Set NewBtn1 = Application.CommandBars("Lenses Design").Controls.Add(Type:=
msoControlButton)
With NewBtn1
.FaceId = 642
.OnAction = "ThisWorkbook.LensDesign"
.Caption = "Design"
.TooltipText = "Design aerodynamic lenses"
.Style = 3
End With
..............

Does anybody know how to solve this problem?
Thanks a lot.
you have to reinstall office
 
H

hedonists

Hi
Thanks for the reply.
Yes, I created the CB using code. Initially I did not declare explicitly
NewBtn1's data type. Then I added
Dim NewBtn1 As CommandBarButton
But this did not make a difference. I look forward to new suggestions from
you!!!

The code I used to generate the tool bar is as follows
Private Sub CreateDesignToolbar()Dim TBar As CommandBarOn Error Resume
NextApplication.CommandBars("Lenses Design").DeleteOn Error GoTo 0Set TBar =
Application.CommandBars.Add With TBar .Name = "Lenses Design"
.Protection = msoBarNoCustomize .Position = msoBarFloating
..Visible = True End WithCall AddDesignButtonEnd Sub
Set NewBtn1
 
J

JE McGimpsey

The problem is that you're trying to customize a button on a bar that
you've set to disallow customization. Remove this line:

.Protection = msoBarNoCustomize

or move it so that it's executed after all your customizations are done.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top