Hi,
I have a VBA script that places WinForm dropdown boxes (xlDropDown) into an excel workbook dynamically. For some reason, on the 17th box (called "INCL" & i + 1 in the code below), the data type of the placed shape becomes msoAutoShape instead of msoFormControl. All of the following controls are msoFormControl again. I've been banging my head on this one. If anyone has any ideas as to why this is happening, that would be great. The problem is that I am able to access te selection in msoFormControl, but not msoAutoShape. Thanks very much.
Sub CreateFormsButton()
Range("A1").Select
Application.StatusBar = "Adding Buttons and Defaults..."
Application.ScreenUpdating = False
Dim curCombo As Excel.Shape
Dim btn As Button
Dim rng As Range
Dim i As Integer
'Select first difference row
With Worksheets("Report")
Set rng = .Range("E2")
i = 0
Do While rng.Value <> ""
Set curCombo = ActiveSheet.Shapes.AddFormControl(xlDropDown, rng.Offset(0, 2).Left, rng.Offset(0, 2).Top, rng.Offset(0, 2).Width, rng.Offset(0, 2).Height)
With curCombo
.ControlFormat.DropDownLines = 10
.ControlFormat.AddItem "RTL", 1
.ControlFormat.AddItem "NW", 2
.ControlFormat.AddItem "Custom 1", 3
.ControlFormat.AddItem "Custom 2", 4
.ControlFormat.AddItem "Custom 3", 5
.ControlFormat.AddItem "002", 6
.ControlFormat.AddItem "13", 7
.ControlFormat.AddItem "1005", 8
.ControlFormat.AddItem "001", 9
.ControlFormat.AddItem "202", 10
.ControlFormat.AddItem "03", 11
.ControlFormat.AddItem "2004", 12
.ControlFormat.AddItem "001", 13
.ControlFormat.AddItem "402", 14
.ControlFormat.AddItem "4004", 15
.ControlFormat.AddItem "405", 16
.ControlFormat.AddItem "None", 17
.Name = "CBOA" & i + 1 '
' .OnAction = "getCboAllocationSelection"
.ControlFormat.ListIndex = 1
End With
Set curCombo = ActiveSheet.Shapes.AddFormControl(xlDropDown, rng.Offset(0, 3).Left, rng.Offset(0, 3).Top, rng.Offset(0, 3).Width, rng.Offset(0, 3).Height)
With curCombo
.ControlFormat.DropDownLines = 10
.ControlFormat.AddItem "NH", 1
.ControlFormat.AddItem "ME", 2
.ControlFormat.AddItem "VT", 3
.ControlFormat.AddItem "TEST", 4
.ControlFormat.AddItem "ALL", 5
.Name = "INCL" & i + 1
'.OnAction = "setInclude"
.ControlFormat.ListIndex = intDefaultAllocateTo
End With
'Clear
Set btn = .Buttons.Add(rng.Offset(0, 4).Left, rng.Offset(0, 4).Top, rng.Offset(0, 4).Width, rng.Offset(0, 4).Height)
With btn
.Caption = "Clear"
.OnAction = "Clear"
.Name = "CLER" & i + 1
End With
'Offset 1 row
Set rng = rng.Offset(1, 0)
i = i + 1
Loop
'Create new range
Dim rng2 As Range
Set rng2 = .Range("K4")
'Add go button
Set btn = .Buttons.Add(rng2.Offset(0, 0).Left, rng2.Offset(0, 0).Top, rng2.Offset(0, 0).Width, rng2.Offset(0, 0).Height * 2)
With btn
.Caption = "Allocate All"
.OnAction = "Allocate"
.Name = "Allocate"
End With
'Add refresh button
Set btn = .Buttons.Add(rng2.Offset(3, 0).Left, rng2.Offset(3, 0).Top, rng2.Offset(3, 0).Width, rng2.Offset(3, 0).Height)
With btn
.Caption = "Refresh Data"
.OnAction = "RefreshData"
.Name = "Allocate"
End With
'Add clear all button
Set btn = .Buttons.Add(rng2.Offset(4, 0).Left, rng2.Offset(4, 0).Top, rng2.Offset(4, 0).Width, rng2.Offset(4, 0).Height)
With btn
.Caption = "Clear All"
.OnAction = "ClearAllOptions"
.Name = "Allocate"
End With
End With
Application.ScreenUpdating = True
'
'Set rng = .Range("H5")
'rng.Select
Application.StatusBar = ""
End Sub