Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default adding button to commandbars crahes Excel when started

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 toolsaddins.. 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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,290
Default adding button to commandbars crahes Excel when started


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"
.(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 toolsaddins.. 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
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default adding button to commandbars crahes Excel when started

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 toolsaddins.. 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
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default adding button to commandbars crahes Excel when started

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" wrote in message
...
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 toolsaddins.. 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



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default adding button to commandbars crahes Excel when started

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" wrote in message
...
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 toolsaddins.. 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
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
adding code to command button in word from excel VBA hornbecky83 Excel Programming 2 January 3rd 07 09:45 PM
CommandBars vs CommandBars(1).Controls Sean Excel Programming 3 April 3rd 06 01:34 PM
Adding .xla button for Toggle Calculation Button Mike Excel Programming 5 August 19th 05 01:55 PM
adding a command button to an excel cell? betelguese Excel Discussion (Misc queries) 1 March 22nd 05 03:09 AM
Adding a button to Excel, need help please yash Excel Programming 1 March 2nd 05 10:43 PM


All times are GMT +1. The time now is 05:17 AM.

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"