ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   In-place CommandBar.Add run-time error (https://www.excelbanter.com/excel-discussion-misc-queries/161409-place-commandbar-add-run-time-error.html)

ARHangel

In-place CommandBar.Add run-time error
 
I have an excel embeded in a word. I edit the excel in-place and i want when
the user tries to open the context menu to show another context menu. But an
error appears: Run-time error '-2147467259 (80004005)':

Method 'Add' of Object '_CommandBars' failed

Here is the method:

Private Sub Worksheet_BeforeRightClick(ByVal Target As Range, Cancel As
Boolean)
Dim myBar As CommandBar
Dim barOpen As CommandBarButton
'''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''
' This is where i get that error
Set myBar = Application.CommandBars.Add(Name:="MyCustomButton" ,
Position:=msoBarMenuBar, temporary:=True)
'''''''''''''''''''''''''''''''''''''''''''''''''
Set barOpen = myBar.Controls.Add(Type:=msoControlButton, ID:=1,
temporary:=True)
With barOpen
.Caption = "Open"
.OnAction = "Sheet1.Open"
End With
End Sub

Is there a way to do this? Do you have another solution?

Thanks

Jim Cone

In-place CommandBar.Add run-time error
 


I have not done what you are attempting, however it may help to specify the
specific application you are referring to - You are in a Word application and
trying to make an Excel application do something, so try ...
Change Application.CommandBars to Excel.Application.CommandBars
--
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware
(Excel Add-ins / Excel Programming)



"ARHangel"
wrote in message
I have an excel embeded in a word. I edit the excel in-place and i want when
the user tries to open the context menu to show another context menu. But an
error appears: Run-time error '-2147467259 (80004005)':

Method 'Add' of Object '_CommandBars' failed

Here is the method:

Private Sub Worksheet_BeforeRightClick(ByVal Target As Range, Cancel As
Boolean)
Dim myBar As CommandBar
Dim barOpen As CommandBarButton
'''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''
' This is where i get that error
Set myBar = Application.CommandBars.Add(Name:="MyCustomButton" ,
Position:=msoBarMenuBar, temporary:=True)
'''''''''''''''''''''''''''''''''''''''''''''''''
Set barOpen = myBar.Controls.Add(Type:=msoControlButton, ID:=1,
temporary:=True)
With barOpen
.Caption = "Open"
.OnAction = "Sheet1.Open"
End With
End Sub

Is there a way to do this? Do you have another solution?
Thanks

ARHangel

In-place CommandBar.Add run-time error
 
Yes I have added a Worksheet in a word and add the Worksheet_BeforeRightClick
in the Worksheet VBA.

I have tried you're solution but still the same error appears.

"Jim Cone" wrote:



I have not done what you are attempting, however it may help to specify the
specific application you are referring to - You are in a Word application and
trying to make an Excel application do something, so try ...
Change Application.CommandBars to Excel.Application.CommandBars
--
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware
(Excel Add-ins / Excel Programming)



"ARHangel"
wrote in message
I have an excel embeded in a word. I edit the excel in-place and i want when
the user tries to open the context menu to show another context menu. But an
error appears: Run-time error '-2147467259 (80004005)':

Method 'Add' of Object '_CommandBars' failed

Here is the method:

Private Sub Worksheet_BeforeRightClick(ByVal Target As Range, Cancel As
Boolean)
Dim myBar As CommandBar
Dim barOpen As CommandBarButton
'''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''
' This is where i get that error
Set myBar = Application.CommandBars.Add(Name:="MyCustomButton" ,
Position:=msoBarMenuBar, temporary:=True)
'''''''''''''''''''''''''''''''''''''''''''''''''
Set barOpen = myBar.Controls.Add(Type:=msoControlButton, ID:=1,
temporary:=True)
With barOpen
.Caption = "Open"
.OnAction = "Sheet1.Open"
End With
End Sub

Is there a way to do this? Do you have another solution?
Thanks


Jim Cone

In-place CommandBar.Add run-time error
 

You either need to be asking your questions in a newsgroup dealing
with Apple computers or you need to change the Position parameter.
From the help file...
"msoBarMenuBar "
"Indicates that the new command bar will replace the system menu bar on the Macintosh"
--
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware
(Excel Add-ins / Excel Programming)



"ARHangel"

wrote in message
Yes I have added a Worksheet in a word and add the Worksheet_BeforeRightClick
in the Worksheet VBA.
I have tried you're solution but still the same error appears.

"Jim Cone" wrote:
I have not done what you are attempting, however it may help to specify the
specific application you are referring to - You are in a Word application and
trying to make an Excel application do something, so try ...
Change Application.CommandBars to Excel.Application.CommandBars
--
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware
(Excel Add-ins / Excel Programming)



"ARHangel"
wrote in message
I have an excel embeded in a word. I edit the excel in-place and i want when
the user tries to open the context menu to show another context menu. But an
error appears: Run-time error '-2147467259 (80004005)':

Method 'Add' of Object '_CommandBars' failed

Here is the method:

Private Sub Worksheet_BeforeRightClick(ByVal Target As Range, Cancel As
Boolean)
Dim myBar As CommandBar
Dim barOpen As CommandBarButton
'''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''
' This is where i get that error
Set myBar = Application.CommandBars.Add(Name:="MyCustomButton" ,
Position:=msoBarMenuBar, temporary:=True)
'''''''''''''''''''''''''''''''''''''''''''''''''
Set barOpen = myBar.Controls.Add(Type:=msoControlButton, ID:=1,
temporary:=True)
With barOpen
.Caption = "Open"
.OnAction = "Sheet1.Open"
End With
End Sub

Is there a way to do this? Do you have another solution?
Thanks


ARHangel

In-place CommandBar.Add run-time error
 
I don't understand you answer.

Why should i post in a different newsgroup?

I don't want this to work on a Apple computer. I don't want to replace the
system menu bar. What i want is to change the context menu that appears on
some special cells.

"Jim Cone" wrote:


You either need to be asking your questions in a newsgroup dealing
with Apple computers or you need to change the Position parameter.
From the help file...
"msoBarMenuBar "
"Indicates that the new command bar will replace the system menu bar on the Macintosh"
--
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware
(Excel Add-ins / Excel Programming)



"ARHangel"

wrote in message
Yes I have added a Worksheet in a word and add the Worksheet_BeforeRightClick
in the Worksheet VBA.
I have tried you're solution but still the same error appears.

"Jim Cone" wrote:
I have not done what you are attempting, however it may help to specify the
specific application you are referring to - You are in a Word application and
trying to make an Excel application do something, so try ...
Change Application.CommandBars to Excel.Application.CommandBars
--
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware
(Excel Add-ins / Excel Programming)



"ARHangel"
wrote in message
I have an excel embeded in a word. I edit the excel in-place and i want when
the user tries to open the context menu to show another context menu. But an
error appears: Run-time error '-2147467259 (80004005)':

Method 'Add' of Object '_CommandBars' failed

Here is the method:

Private Sub Worksheet_BeforeRightClick(ByVal Target As Range, Cancel As
Boolean)
Dim myBar As CommandBar
Dim barOpen As CommandBarButton
'''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''
' This is where i get that error
Set myBar = Application.CommandBars.Add(Name:="MyCustomButton" ,
Position:=msoBarMenuBar, temporary:=True)
'''''''''''''''''''''''''''''''''''''''''''''''''
Set barOpen = myBar.Controls.Add(Type:=msoControlButton, ID:=1,
temporary:=True)
With barOpen
.Caption = "Open"
.OnAction = "Sheet1.Open"
End With
End Sub

Is there a way to do this? Do you have another solution?
Thanks




All times are GMT +1. The time now is 06:09 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com