Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 29
Default macro works on F8 but not auto

Macro written to delete an addition to commandbar(1):

When it is invoked through the .onaction property that is
defined when the menu item is added, the delete item
macro fails. The error message is -2147467259(80004005)
Method 'Delete' of object 'CommandBarPopup' failed.

Strangely though, if I step through the macro
incrementally (F8 F8 F8...) it works fine.

I can't figure this one out.

Thanks for any help!

Neil
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 176
Default macro works on F8 but not auto

Neil,

Post your code.

HTH,
Bernie
MS Excel MVP

"Neil" wrote in message
...
Macro written to delete an addition to commandbar(1):

When it is invoked through the .onaction property that is
defined when the menu item is added, the delete item
macro fails. The error message is -2147467259(80004005)
Method 'Delete' of object 'CommandBarPopup' failed.

Strangely though, if I step through the macro
incrementally (F8 F8 F8...) it works fine.

I can't figure this one out.

Thanks for any help!

Neil



  #3   Report Post  
Posted to microsoft.public.excel.programming
No Name
 
Posts: n/a
Default macro works on F8 but not auto

Here's the code...

Sub addtomenu()

Dim dubam As CommandBarControl

Set dubam = CommandBars(1).Controls.Add
(Type:=msoControlPopup)
dubam.Caption = "Return to DUBAM"
With dubam
.OnAction = "deletefrommenu"
End With


End Sub


Sub deletefrommenu()
Dim menuitem As CommandBarControl
Dim count As Integer

For Each menuitem In CommandBars(1).Controls
count = count + 1
Set menuitem = CommandBars(1).Controls(count)
If menuitem.BuiltIn = False Then
menuitem.Delete
End If
Next

Call go


End Sub

-----Original Message-----
Neil,

Post your code.

HTH,
Bernie
MS Excel MVP

"Neil" wrote in

message
...
Macro written to delete an addition to commandbar(1):

When it is invoked through the .onaction property that

is
defined when the menu item is added, the delete item
macro fails. The error message is -2147467259

(80004005)
Method 'Delete' of object 'CommandBarPopup' failed.

Strangely though, if I step through the macro
incrementally (F8 F8 F8...) it works fine.

I can't figure this one out.

Thanks for any help!

Neil



.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 176
Default macro works on F8 but not auto

Neil,

As soon as you delete a control, that throws off your upper limit on the Do
loop. You need to go in reverse order. I'm not sure why it works by
stepping through, but I'm sure why it doesn't work in regular execution:

For Count = CommandBars(1).Controls.Count To 1 Step -1
Set menuitem = CommandBars(1).Controls(Count)
If menuitem.BuiltIn = False Then menuitem.Delete
Next Count

HTH,
Bernie
MS Excel MVP

wrote in message
...
Here's the code...

Sub addtomenu()

Dim dubam As CommandBarControl

Set dubam = CommandBars(1).Controls.Add
(Type:=msoControlPopup)
dubam.Caption = "Return to DUBAM"
With dubam
.OnAction = "deletefrommenu"
End With


End Sub


Sub deletefrommenu()
Dim menuitem As CommandBarControl
Dim count As Integer

For Each menuitem In CommandBars(1).Controls
count = count + 1
Set menuitem = CommandBars(1).Controls(count)
If menuitem.BuiltIn = False Then
menuitem.Delete
End If
Next

Call go


End Sub

-----Original Message-----
Neil,

Post your code.

HTH,
Bernie
MS Excel MVP

"Neil" wrote in

message
...
Macro written to delete an addition to commandbar(1):

When it is invoked through the .onaction property that

is
defined when the menu item is added, the delete item
macro fails. The error message is -2147467259

(80004005)
Method 'Delete' of object 'CommandBarPopup' failed.

Strangely though, if I step through the macro
incrementally (F8 F8 F8...) it works fine.

I can't figure this one out.

Thanks for any help!

Neil



.



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 29
Default macro works on F8 but not auto

Bernie - thanks, but it still worked the same way...step
through is fine, but regular execution same error.

Did this code work for you? Perhaps it is a XP or Excel
2002 bug...

I can just change the type to floating...but I dislike
unresolved problems...

Neil

-----Original Message-----
Neil,

As soon as you delete a control, that throws off your

upper limit on the Do
loop. You need to go in reverse order. I'm not sure why

it works by
stepping through, but I'm sure why it doesn't work in

regular execution:

For Count = CommandBars(1).Controls.Count To 1 Step -1
Set menuitem = CommandBars(1).Controls(Count)
If menuitem.BuiltIn = False Then menuitem.Delete
Next Count

HTH,
Bernie
MS Excel MVP

wrote in message
...
Here's the code...

Sub addtomenu()

Dim dubam As CommandBarControl

Set dubam = CommandBars(1).Controls.Add
(Type:=msoControlPopup)
dubam.Caption = "Return to DUBAM"
With dubam
.OnAction = "deletefrommenu"
End With


End Sub


Sub deletefrommenu()
Dim menuitem As CommandBarControl
Dim count As Integer

For Each menuitem In CommandBars(1).Controls
count = count + 1
Set menuitem = CommandBars(1).Controls(count)
If menuitem.BuiltIn = False Then
menuitem.Delete
End If
Next

Call go


End Sub

-----Original Message-----
Neil,

Post your code.

HTH,
Bernie
MS Excel MVP

"Neil" wrote in

message
...
Macro written to delete an addition to commandbar

(1):

When it is invoked through the .onaction property

that
is
defined when the menu item is added, the delete item
macro fails. The error message is -2147467259

(80004005)
Method 'Delete' of object 'CommandBarPopup' failed.

Strangely though, if I step through the macro
incrementally (F8 F8 F8...) it works fine.

I can't figure this one out.

Thanks for any help!

Neil


.



.



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 29
Default macro works on F8 but not auto: more info

I ran a couple of tests...

If there were two menu items with builtin=false, the
first one deletes, the second one errors out. It seems
that if there is only one custom item, there is a problem
deleting it.

Placement does not seem to matter - I had thought that
maybe there was a problem with the "last" menu item.

I'm relatively new to VB programming (6 weeks) so I don't
know where to go with this info.

Neil


-----Original Message-----
Neil,

As soon as you delete a control, that throws off your

upper limit on the Do
loop. You need to go in reverse order. I'm not sure why

it works by
stepping through, but I'm sure why it doesn't work in

regular execution:

For Count = CommandBars(1).Controls.Count To 1 Step -1
Set menuitem = CommandBars(1).Controls(Count)
If menuitem.BuiltIn = False Then menuitem.Delete
Next Count

HTH,
Bernie
MS Excel MVP

wrote in message
...
Here's the code...

Sub addtomenu()

Dim dubam As CommandBarControl

Set dubam = CommandBars(1).Controls.Add
(Type:=msoControlPopup)
dubam.Caption = "Return to DUBAM"
With dubam
.OnAction = "deletefrommenu"
End With


End Sub


Sub deletefrommenu()
Dim menuitem As CommandBarControl
Dim count As Integer

For Each menuitem In CommandBars(1).Controls
count = count + 1
Set menuitem = CommandBars(1).Controls(count)
If menuitem.BuiltIn = False Then
menuitem.Delete
End If
Next

Call go


End Sub

-----Original Message-----
Neil,

Post your code.

HTH,
Bernie
MS Excel MVP

"Neil" wrote in

message
...
Macro written to delete an addition to commandbar

(1):

When it is invoked through the .onaction property

that
is
defined when the menu item is added, the delete item
macro fails. The error message is -2147467259

(80004005)
Method 'Delete' of object 'CommandBarPopup' failed.

Strangely though, if I step through the macro
incrementally (F8 F8 F8...) it works fine.

I can't figure this one out.

Thanks for any help!

Neil


.



.

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 176
Default macro works on F8 but not auto: more info

Neil,

How about trying to step through the controls:

Sub DeleteCustomButtons()
Dim CmdBar As CommandBar
Dim myCont As CommandBarControl
Set CmdBar = Application.CommandBars(1)
For Each myCont In CmdBar.Controls
If myCont.BuiltIn = False Then
myCont.Delete
End If
Next myCont
End Sub

HTH,
Bernie
MS Excel MVP

"Neil" wrote in message
...
I ran a couple of tests...

If there were two menu items with builtin=false, the
first one deletes, the second one errors out. It seems
that if there is only one custom item, there is a problem
deleting it.

Placement does not seem to matter - I had thought that
maybe there was a problem with the "last" menu item.

I'm relatively new to VB programming (6 weeks) so I don't
know where to go with this info.

Neil


-----Original Message-----
Neil,

As soon as you delete a control, that throws off your

upper limit on the Do
loop. You need to go in reverse order. I'm not sure why

it works by
stepping through, but I'm sure why it doesn't work in

regular execution:

For Count = CommandBars(1).Controls.Count To 1 Step -1
Set menuitem = CommandBars(1).Controls(Count)
If menuitem.BuiltIn = False Then menuitem.Delete
Next Count

HTH,
Bernie
MS Excel MVP

wrote in message
...
Here's the code...

Sub addtomenu()

Dim dubam As CommandBarControl

Set dubam = CommandBars(1).Controls.Add
(Type:=msoControlPopup)
dubam.Caption = "Return to DUBAM"
With dubam
.OnAction = "deletefrommenu"
End With


End Sub


Sub deletefrommenu()
Dim menuitem As CommandBarControl
Dim count As Integer

For Each menuitem In CommandBars(1).Controls
count = count + 1
Set menuitem = CommandBars(1).Controls(count)
If menuitem.BuiltIn = False Then
menuitem.Delete
End If
Next

Call go


End Sub

-----Original Message-----
Neil,

Post your code.

HTH,
Bernie
MS Excel MVP

"Neil" wrote in
message
...
Macro written to delete an addition to commandbar

(1):

When it is invoked through the .onaction property

that
is
defined when the menu item is added, the delete item
macro fails. The error message is -2147467259
(80004005)
Method 'Delete' of object 'CommandBarPopup' failed.

Strangely though, if I step through the macro
incrementally (F8 F8 F8...) it works fine.

I can't figure this one out.

Thanks for any help!

Neil


.



.



  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 29
Default macro works on F8 but not auto: more info

Bernie - no luck there either. However, I did find a
less elegant way...

commandbars(1).reset

I stumbled across this as I was running some tests and
accidentally deleted all the built in items (which I
thought you were not supposed to be able to do...). I
paniced for a second but then figured there must be a way
to reset...found that, restored the built ins and then
realized....

Thanks for the help.

Neil

-----Original Message-----
Neil,

How about trying to step through the controls:

Sub DeleteCustomButtons()
Dim CmdBar As CommandBar
Dim myCont As CommandBarControl
Set CmdBar = Application.CommandBars(1)
For Each myCont In CmdBar.Controls
If myCont.BuiltIn = False Then
myCont.Delete
End If
Next myCont
End Sub

HTH,
Bernie
MS Excel MVP

"Neil" wrote in

message
...
I ran a couple of tests...

If there were two menu items with builtin=false, the
first one deletes, the second one errors out. It seems
that if there is only one custom item, there is a

problem
deleting it.

Placement does not seem to matter - I had thought that
maybe there was a problem with the "last" menu item.

I'm relatively new to VB programming (6 weeks) so I

don't
know where to go with this info.

Neil


-----Original Message-----
Neil,

As soon as you delete a control, that throws off your

upper limit on the Do
loop. You need to go in reverse order. I'm not sure

why
it works by
stepping through, but I'm sure why it doesn't work in

regular execution:

For Count = CommandBars(1).Controls.Count To 1 Step -1
Set menuitem = CommandBars(1).Controls(Count)
If menuitem.BuiltIn = False Then menuitem.Delete
Next Count

HTH,
Bernie
MS Excel MVP

wrote in message
...
Here's the code...

Sub addtomenu()

Dim dubam As CommandBarControl

Set dubam = CommandBars(1).Controls.Add
(Type:=msoControlPopup)
dubam.Caption = "Return to DUBAM"
With dubam
.OnAction = "deletefrommenu"
End With


End Sub


Sub deletefrommenu()
Dim menuitem As CommandBarControl
Dim count As Integer

For Each menuitem In CommandBars(1).Controls
count = count + 1
Set menuitem = CommandBars(1).Controls(count)
If menuitem.BuiltIn = False Then
menuitem.Delete
End If
Next

Call go


End Sub

-----Original Message-----
Neil,

Post your code.

HTH,
Bernie
MS Excel MVP

"Neil" wrote

in
message
...
Macro written to delete an addition to commandbar

(1):

When it is invoked through the .onaction property

that
is
defined when the menu item is added, the delete

item
macro fails. The error message is -2147467259
(80004005)
Method 'Delete' of object 'CommandBarPopup'

failed.

Strangely though, if I step through the macro
incrementally (F8 F8 F8...) it works fine.

I can't figure this one out.

Thanks for any help!

Neil


.



.



.

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Worksheet protected-auto filter works, show all button dosen't. Pink Gorman Excel Discussion (Misc queries) 2 August 20th 08 05:42 PM
Macro works Macro does not work Wanna Learn Excel Discussion (Misc queries) 4 March 24th 08 12:51 PM
Macro works but buttons don't markvi Excel Discussion (Misc queries) 0 June 8th 06 09:19 PM
macro works for some users and doesn't for others Pooja Excel Discussion (Misc queries) 2 October 27th 05 08:27 PM
macro works in .xlt but not .xls BrianG[_3_] Excel Programming 6 September 18th 03 10:13 PM


All times are GMT +1. The time now is 01:40 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"