Objects(Images) Restated

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
 
P

Perry

To counter the ActiveX controls on the document,
from a multitude of possibilties, here's one:

Place this routine in ThisDocument module
Sub testing()
Dim ils As InlineShape
For Each ils In Me.InlineShapes
MsgBox ils.OLEFormat.ProgID
Next
End Sub

Now from the UserForm code module, you can access this routine
thus enumerating all ActiveX controls on yr document.
In below example, I've used the UserForm_Click to make the call

Private Sub UserForm_Click()
ActiveDocument.testing
End Sub

Krgrds,
Perry
 
J

James

But can I use this to identify the control (image) by
name? So that if "Image1" is found, an item is added to a
combobox in my userform. And when I try to add an item to
a combobox (for instance, after the MsgBox segment) I get
an object required error.

In addition, this must work in the Initialize event of
the userform, which is where I put the
activedocument.testing sub, so that every time the
userform is opened, its comboboxes are filled with the
appropriate items.
 
P

Perry

There's no name property for images you can utilize.
You can however -as a workaround- use the Alternative Text property
of inline shapes, as examplified below:

'load the combo
Private Sub UserForm_Initialize()
Dim ils As InlineShape
For Each ils In ActiveDocument.InlineShapes
Me.ComboBox1.AddItem ils.AlternativeText
Next
End Sub

'identify the image
Private Sub CommandButton1_Click()
Dim ils As InlineShape
For Each ils In ActiveDocument.InlineShapes
If ils.AlternativeText = Me.ComboBox1 Then
'do the actions
End If
Next
End Sub

Krgrds,
Perry
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top