LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 19
Default Code Crashing

When I run the following code it sometimes crashes on the first line
after the for loop start. The code adds/removes some menu items from
the 3 cell right click menus(There are 3 right click cell menus, one
for when a cell or area of cells are selected, one for entier row(s)
selected, and one for entire column(s) selected). I can get it to run
the line of code by debugging, then making the particular menu show
once, and then resuming the code. I can't get the error to repeat
consistently. Any ideas are appreciated. Thanks.


Code:
Sub Setup_Right_Click_Items()
    Dim InsertIndex As Integer
    Dim NewItem As CommandBarButton
    Dim myIndex As CommandBarControl
    Dim MenuArray

    ReDim MenuArray(1 To 2, 1 To 3)
    MenuArray(1, 1) = "Cell"
    MenuArray(2, 1) = "Insert..."
    MenuArray(1, 2) = "Row"
    MenuArray(2, 2) = "Insert"
    MenuArray(1, 3) = "Column"
    MenuArray(2, 3) = "Insert"

    For i = 1 To 3
        Set myIndex = CommandBars(MenuArray(1,
i)).Controls(MenuArray(2, i))    '<--crashes here

        On Error Resume Next
            CommandBars(MenuArray(1, i)).Controls("Toggle
Merge").Delete
            CommandBars(MenuArray(1, i)).Controls("Toggle
Wrap").Delete
            CommandBars(MenuArray(1, i)).Controls("Paste As
Values").Delete

            ' default items i remove
            CommandBars(MenuArray(1, i)).Controls("Pick From Drop-down
List...").Delete
            CommandBars(MenuArray(1, i)).Controls("Add Watch").Delete
            CommandBars(MenuArray(1, i)).Controls("Create
List...").Delete
            CommandBars(MenuArray(1,
i)).Controls("Hyperlink...").Delete
            CommandBars(MenuArray(1, i)).Controls("Look Up...").Delete
        On Error GoTo 0

        ' move format cells to top
        On Error Resume Next
            CommandBars(MenuArray(1, i)).Controls("Format
Cells...").Delete
        On Error GoTo 0
        Set NewItem = Application.CommandBars(MenuArray(1,
i)).Controls.Add(ID:=855, befo=1)
        With NewItem
            .Caption = "Format Cells..."
        End With
        Set NewItem = Application.CommandBars(MenuArray(1,
i)).Controls("Cut")
        With NewItem
            .BeginGroup = True
        End With

        ' Set up my addins
        InsertIndex = myIndex.Index

        Set NewItem = Application.CommandBars(MenuArray(1,
i)).Controls.Add(ID:=370, befo=InsertIndex)
        With NewItem
            .Caption = "Paste as Values"
            .FaceId = 0
        End With

        InsertIndex = myIndex.Index

        Set NewItem = Application.CommandBars(MenuArray(1,
i)).Controls.Add(befo=InsertIndex)
        With NewItem
            .Caption = "Toggle Wrap"
            .OnAction = "Toggle_Wrap"
            .BeginGroup = True
        End With

        InsertIndex = myIndex.Index

        Set NewItem = Application.CommandBars(MenuArray(1,
i)).Controls.Add(befo=InsertIndex)
        With NewItem
            .Caption = "Toggle Merge"
            .OnAction = "Toggle_Merge"
        End With
    Next i
End Sub
 
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
code crashing my programme??????? Tdp Excel Discussion (Misc queries) 4 October 30th 08 10:34 AM
Crashing!!! Pasty Excel Programming 1 March 16th 07 12:48 PM
vb exe crashing kasi Excel Programming 1 October 15th 05 03:33 AM
VBA code silently crashing. Problem with Data Validation drop down lists. Don Wiss Excel Programming 6 February 27th 05 09:46 AM
"Tabbing" code crashing xl2002 WinXP Matt Jensen[_2_] Excel Programming 2 January 14th 05 03:16 PM


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

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

About Us

"It's about Microsoft Excel"