custom toolbar error
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:
..............
Private Sub CreateDesignToolbar()
Dim TBar As CommandBar
On Error Resume Next
Application.CommandBars("Lenses Design").Delete
On Error GoTo 0
Set TBar = Application.CommandBars.Add
With TBar
.Name = "Lenses Design"
.Protection = msoBarNoCustomize
.Position = msoBarFloating
.Visible = True
End With
Call AddDesignButton
End Sub
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.
[1344 byte] By [
hedonist] at [2007-12-18]
Again, this might be a repeat of Will's post, but here's what I got back from our support engineer:
Here’s my update regarding following issue. Base on my understanding, our buddy has two questions. One is regarding to the statement “.FaceId = 642” and the other is for ‘OnAction’ property.
I tested our buddy’s code on Mac. We can get the No. 642 resource and render into the icon of a CommandBarButton. However, I think the key issue is “OnAction = "ThisWorkbook.LensDesign"”. Please change to “OnAction = "LensDesign"” and try again. I suppose “LensDesign” must be an existing custom function. J
Anything unclear, please feel free to let me know. Thanks. Regards, Ming
-brenda (ISV Buddy Team)
Hi,
Thanks for the reply.
I tried to change “OnAction = "ThisWorkbook.LensDesign"”. Please change to “OnAction = "LensDesign"”.
Then I found it does not even work in Windows Excel. When I click
another worksheet and then return to this worksheet, I got an error
message saying that "The Macro Filename.xls'!LensDesign' cannot
be found" when I click the button. The toolbar still did not load in
Mac Excel.
I look forward to hearing more from you. I can email the excel file to you if you can give me your email address.
Thanks again, to you and the ISV Buddy Team.
Per the support engineer:
That’s great to have the source code! I looked into our buddy’s code (big code…J). Here’s my update:
Our buddy set the Protection property of CommandBar to msoBarNoCustomize, which will cause this problem on MacExcel. Following is his code, let’s comment the line in bold first and have a try again. J
==================================
Private Sub CreateDesignToolbar()
Dim TBar As CommandBar
On Error Resume Next
Application.CommandBars("Lenses Design").Delete
On Error GoTo 0
Set TBar = Application.CommandBars.Add
With TBar
.Name = "Lenses Design"
‘.Protection = msoBarNoCustomize
.Position = msoBarFloating
.Visible = True
End With
Call AddDesignButton
End Sub
Private Sub CreateTestToolbar()
Dim TBar As CommandBar
On Error Resume Next
Application.CommandBars("Lenses Test").Delete
On Error GoTo 0
Set TBar = Application.CommandBars.Add
With TBar
.Name = "Lenses Test"
‘ .Protection = msoBarNoCustomize
.Position = msoBarFloating
.Visible = True
End With
Call AddTestButton
End Sub
=================================
-brenda (ISV Buddy Team)