vba - Excel crashes when running a loop to disable controls -
public sub optionsdisable() dim mycontrols commandbarcontrols dim ctl commandbarcontrol dim iarray(21, 3181, 292, 3125, 855, 1576, 293, 541, 3183, 294, 542, 886, 887, 883, 884) long dim myelement variant each myelement in iarray set mycontrols = commandbars.findcontrols _ (type:=msocontrolbutton, id:=myelement) if not mycontrols nothing each ctl in mycontrols ctl.enabled = false next ctl end if next end sub okay everyone, when run subroutine, excel crashes. trying run through loop disable every control id in array. i'm thinking happening is entering infinite loop, set breakpoint on first line statement, , still crashes, before gets there. so, other guess it's problem array , or variant defining. anyone have idea? p.s. running code crash excel. try this: public sub optionsdisable() dim mycontrols commandbarcontrols dim ctl commandbarcontrol dim iarray va...