PC Review


Reply
Thread Tools Rate Thread

adding button to commandbars crahes Excel when started

 
 
=?Utf-8?B?QnJhZCBDYXJtYW4=?=
Guest
Posts: n/a
 
      26th Jan 2007
I have a subroutine that is called from an Auto_Open subroutine that is shown
below. I have narrowed it down to this code as being the reason for excel
crashing on startup. Excel recoginizes that my Addin is the reason for the
problem and askes if I want to disable it. When that is done Excel starts
just fine. When I go to tools>addins.. and start my Addin up everything runs
fine, no errors are encountered. So why does this code create an error when
excel is starting as compared to after it has finished booting up? Thanks
for any help!! Here is my code...

Sub CreateRightClick()
Dim btn As CommandBarButton
Dim btn2 As CommandBarButton
Dim barArray As Variant
Dim i
barArray = Array("List Range Popup", "Cell", "Column", "Row")

For i = LBound(barArray) To UBound(barArray)
With Application.CommandBars(barArray(i))
.Reset
Set btn = .Controls.Add(Temporary:=True)
btn.BeginGroup = True
btn.Caption = "Apply Throughout"
btn.OnAction = "ApplyThroughout"
btn.FaceId = 201
Set btn2 = .Controls.Add(Temporary:=True)
btn2.Caption = "Calculate Cells"
btn2.OnAction = "ReCalcHighlighted"
btn2.FaceId = 202
End With
Set btn = Nothing
Set btn2 = Nothing
Next i
End Sub
 
Reply With Quote
 
 
 
 
Jim Cone
Guest
Posts: n/a
 
      26th Jan 2007

Well the first thing that comes to mind is the possibility that
the machine with the problem is not running Excel 2003.
If it is running XL 2003, then what happens if you stick an
"on error resume next" in the code?
That could possibly pinpoint the problem area for you, if a button or
something else is missing.
--
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware



"Brad Carman"
<(E-Mail Removed).(donotspam)>
wrote in message
I have a subroutine that is called from an Auto_Open subroutine that is shown
below. I have narrowed it down to this code as being the reason for excel
crashing on startup. Excel recoginizes that my Addin is the reason for the
problem and askes if I want to disable it. When that is done Excel starts
just fine. When I go to tools>addins.. and start my Addin up everything runs
fine, no errors are encountered. So why does this code create an error when
excel is starting as compared to after it has finished booting up? Thanks
for any help!! Here is my code...

Sub CreateRightClick()
Dim btn As CommandBarButton
Dim btn2 As CommandBarButton
Dim barArray As Variant
Dim i
barArray = Array("List Range Popup", "Cell", "Column", "Row")

For i = LBound(barArray) To UBound(barArray)
With Application.CommandBars(barArray(i))
.Reset
Set btn = .Controls.Add(Temporary:=True)
btn.BeginGroup = True
btn.Caption = "Apply Throughout"
btn.OnAction = "ApplyThroughout"
btn.FaceId = 201
Set btn2 = .Controls.Add(Temporary:=True)
btn2.Caption = "Calculate Cells"
btn2.OnAction = "ReCalcHighlighted"
btn2.FaceId = 202
End With
Set btn = Nothing
Set btn2 = Nothing
Next i
End Sub
 
Reply With Quote
 
Dave Peterson
Guest
Posts: n/a
 
      26th Jan 2007
I've seen posts that say that excel can get "confused" while starting up. Some
pretty smart people have recommended this kind of thing.

Sub Auto_Open()
Application.OnTime Now, "Continue_Open"
End Sub

Then in a general module:

sub Continue_Open()
'your real code here
end sub

Maybe this'll avoid any "timing" issues that excel is having??????

Good luck.


Brad Carman wrote:
>
> I have a subroutine that is called from an Auto_Open subroutine that is shown
> below. I have narrowed it down to this code as being the reason for excel
> crashing on startup. Excel recoginizes that my Addin is the reason for the
> problem and askes if I want to disable it. When that is done Excel starts
> just fine. When I go to tools>addins.. and start my Addin up everything runs
> fine, no errors are encountered. So why does this code create an error when
> excel is starting as compared to after it has finished booting up? Thanks
> for any help!! Here is my code...
>
> Sub CreateRightClick()
> Dim btn As CommandBarButton
> Dim btn2 As CommandBarButton
> Dim barArray As Variant
> Dim i
> barArray = Array("List Range Popup", "Cell", "Column", "Row")
>
> For i = LBound(barArray) To UBound(barArray)
> With Application.CommandBars(barArray(i))
> .Reset
> Set btn = .Controls.Add(Temporary:=True)
> btn.BeginGroup = True
> btn.Caption = "Apply Throughout"
> btn.OnAction = "ApplyThroughout"
> btn.FaceId = 201
> Set btn2 = .Controls.Add(Temporary:=True)
> btn2.Caption = "Calculate Cells"
> btn2.OnAction = "ReCalcHighlighted"
> btn2.FaceId = 202
> End With
> Set btn = Nothing
> Set btn2 = Nothing
> Next i
> End Sub


--

Dave Peterson
 
Reply With Quote
 
Peter T
Guest
Posts: n/a
 
      27th Jan 2007
If Dave's suggestion works it's probably due to your (Brad) "Reset" of one
or more of the popup Commands, designed to work on a visible worksheet while
no such worksheet exists. The default buttons on these change according to
scenarios, egg the Insert.

Instead of resetting, particularly if you are distributing to users who may
not want their popups reset, consider attempting to delete your own buttons
under 'On Error Resume Next' then go on to add them. Alternatively attempt
to set a reference to them, if the ref succeeds re-apply your button
properties as you would had you just added the button.

Regards,
Peter T


"Dave Peterson" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> I've seen posts that say that excel can get "confused" while starting up.

Some
> pretty smart people have recommended this kind of thing.
>
> Sub Auto_Open()
> Application.OnTime Now, "Continue_Open"
> End Sub
>
> Then in a general module:
>
> sub Continue_Open()
> 'your real code here
> end sub
>
> Maybe this'll avoid any "timing" issues that excel is having??????
>
> Good luck.
>
>
> Brad Carman wrote:
> >
> > I have a subroutine that is called from an Auto_Open subroutine that is

shown
> > below. I have narrowed it down to this code as being the reason for

excel
> > crashing on startup. Excel recoginizes that my Addin is the reason for

the
> > problem and askes if I want to disable it. When that is done Excel

starts
> > just fine. When I go to tools>addins.. and start my Addin up everything

runs
> > fine, no errors are encountered. So why does this code create an error

when
> > excel is starting as compared to after it has finished booting up?

Thanks
> > for any help!! Here is my code...
> >
> > Sub CreateRightClick()
> > Dim btn As CommandBarButton
> > Dim btn2 As CommandBarButton
> > Dim barArray As Variant
> > Dim i
> > barArray = Array("List Range Popup", "Cell", "Column", "Row")
> >
> > For i = LBound(barArray) To UBound(barArray)
> > With Application.CommandBars(barArray(i))
> > .Reset
> > Set btn = .Controls.Add(Temporary:=True)
> > btn.BeginGroup = True
> > btn.Caption = "Apply Throughout"
> > btn.OnAction = "ApplyThroughout"
> > btn.FaceId = 201
> > Set btn2 = .Controls.Add(Temporary:=True)
> > btn2.Caption = "Calculate Cells"
> > btn2.OnAction = "ReCalcHighlighted"
> > btn2.FaceId = 202
> > End With
> > Set btn = Nothing
> > Set btn2 = Nothing
> > Next i
> > End Sub

>
> --
>
> Dave Peterson



 
Reply With Quote
 
=?Utf-8?B?QnJhZCBDYXJtYW4=?=
Guest
Posts: n/a
 
      29th Jan 2007
Removing the reset command did the trick! Thanks everyone.

"Peter T" wrote:

> If Dave's suggestion works it's probably due to your (Brad) "Reset" of one
> or more of the popup Commands, designed to work on a visible worksheet while
> no such worksheet exists. The default buttons on these change according to
> scenarios, egg the Insert.
>
> Instead of resetting, particularly if you are distributing to users who may
> not want their popups reset, consider attempting to delete your own buttons
> under 'On Error Resume Next' then go on to add them. Alternatively attempt
> to set a reference to them, if the ref succeeds re-apply your button
> properties as you would had you just added the button.
>
> Regards,
> Peter T
>
>
> "Dave Peterson" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > I've seen posts that say that excel can get "confused" while starting up.

> Some
> > pretty smart people have recommended this kind of thing.
> >
> > Sub Auto_Open()
> > Application.OnTime Now, "Continue_Open"
> > End Sub
> >
> > Then in a general module:
> >
> > sub Continue_Open()
> > 'your real code here
> > end sub
> >
> > Maybe this'll avoid any "timing" issues that excel is having??????
> >
> > Good luck.
> >
> >
> > Brad Carman wrote:
> > >
> > > I have a subroutine that is called from an Auto_Open subroutine that is

> shown
> > > below. I have narrowed it down to this code as being the reason for

> excel
> > > crashing on startup. Excel recoginizes that my Addin is the reason for

> the
> > > problem and askes if I want to disable it. When that is done Excel

> starts
> > > just fine. When I go to tools>addins.. and start my Addin up everything

> runs
> > > fine, no errors are encountered. So why does this code create an error

> when
> > > excel is starting as compared to after it has finished booting up?

> Thanks
> > > for any help!! Here is my code...
> > >
> > > Sub CreateRightClick()
> > > Dim btn As CommandBarButton
> > > Dim btn2 As CommandBarButton
> > > Dim barArray As Variant
> > > Dim i
> > > barArray = Array("List Range Popup", "Cell", "Column", "Row")
> > >
> > > For i = LBound(barArray) To UBound(barArray)
> > > With Application.CommandBars(barArray(i))
> > > .Reset
> > > Set btn = .Controls.Add(Temporary:=True)
> > > btn.BeginGroup = True
> > > btn.Caption = "Apply Throughout"
> > > btn.OnAction = "ApplyThroughout"
> > > btn.FaceId = 201
> > > Set btn2 = .Controls.Add(Temporary:=True)
> > > btn2.Caption = "Calculate Cells"
> > > btn2.OnAction = "ReCalcHighlighted"
> > > btn2.FaceId = 202
> > > End With
> > > Set btn = Nothing
> > > Set btn2 = Nothing
> > > Next i
> > > End Sub

> >
> > --
> >
> > Dave Peterson

>
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
2nd Pivot Table on Worksheet Crahes Excel Tom Davis Microsoft Excel Crashes 1 11th Dec 2009 03:56 PM
Adding and Deleting custom commandbars =?Utf-8?B?d2h5bGl0ZQ==?= Microsoft Excel Programming 3 10th Sep 2007 06:14 PM
how to disable the Options Button in Commandbars (Excel 2003) heinz Microsoft Excel Programming 1 31st Mar 2004 01:33 PM
Adding CommandBars to an Inspector while using Outlook as the editor David McNealey Microsoft Outlook 6 16th Oct 2003 09:17 PM
Adding CommandBars to an Inspector while using Outlook as the editor David McNealey Microsoft Outlook Discussion 6 16th Oct 2003 09:17 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:25 AM.