Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
adding code to command button in word from excel VBA | Excel Programming | |||
CommandBars vs CommandBars(1).Controls | Excel Programming | |||
Adding .xla button for Toggle Calculation Button | Excel Programming | |||
adding a command button to an excel cell? | Excel Discussion (Misc queries) | |||
Adding a button to Excel, need help please | Excel Programming |