J
James
In the initialize event of a UserForm, I would like to
test for the existence of certain
images in a document inserted from the controls toolbox.
If the image in question exists, I would like to add an
item to the userform.
Here is my attempt. Of course the For Each Next that is I
would like to perform this action doesn't work, so how
can I modify it so that it does? For instance, I think it
is searching for controls on the userform, not in the
document, but I haven't had success getting it to search
for controls in the document. Do I have to search for a
Shape object instead? And I am not sure that if it found
the control (or shape) that it would properly insert
the "item" in the userform combobox.
Private Sub UserForm_Initialize()
MultiPage1.Value = 0
Multipage1_Change
'Search for Image and add to combobox
Dim MyControl As Control
For Each MyControl In Controls
If MyControl.Name = "Image1" Then
With UserForm1.ComboBox1
.AddItem "Item"
End With
End If
Next
For Each oControl In Me.Controls
If TypeOf oControl Is MSForms.combobox Then
With oControl
.AddItem "Make a Selection"
.Style = fmStyleDropDownList
.ListIndex = 0
If .ListCount <= 1 Then
.Enabled = False
.Enabled = False
Else
.Enabled = True
.Enabled = True
End If
End With
End If
Next oControl
If ComboBox1.Value <> "Make a Selection" Then
If combobox <> ComboBox1 Then
combobox.Enabled = False
End If
End If
'etc
End Sub
Any help is greatly appreciated
test for the existence of certain
images in a document inserted from the controls toolbox.
If the image in question exists, I would like to add an
item to the userform.
Here is my attempt. Of course the For Each Next that is I
would like to perform this action doesn't work, so how
can I modify it so that it does? For instance, I think it
is searching for controls on the userform, not in the
document, but I haven't had success getting it to search
for controls in the document. Do I have to search for a
Shape object instead? And I am not sure that if it found
the control (or shape) that it would properly insert
the "item" in the userform combobox.
Private Sub UserForm_Initialize()
MultiPage1.Value = 0
Multipage1_Change
'Search for Image and add to combobox
Dim MyControl As Control
For Each MyControl In Controls
If MyControl.Name = "Image1" Then
With UserForm1.ComboBox1
.AddItem "Item"
End With
End If
Next
For Each oControl In Me.Controls
If TypeOf oControl Is MSForms.combobox Then
With oControl
.AddItem "Make a Selection"
.Style = fmStyleDropDownList
.ListIndex = 0
If .ListCount <= 1 Then
.Enabled = False
.Enabled = False
Else
.Enabled = True
.Enabled = True
End If
End With
End If
Next oControl
If ComboBox1.Value <> "Make a Selection" Then
If combobox <> ComboBox1 Then
combobox.Enabled = False
End If
End If
'etc
End Sub
Any help is greatly appreciated