Select Image in Form

G

Greg Maxey

The other day there was a question here about providing a dropdown menu in a
form where a user could select from a graphic vice a text item. I suggested
that perhaps a userform with picture controls would work. I tested this
this morning. I found a few simply road sign .gif images and saved them on
my desktop

Using Word2003. I added a macro button to the form to call the userform and
a bookmark to display the graphic that the user selected. In the userform I
created four picture controls and added a road sign image to each one. The
code in the userform is as follows:

Option Explicit
Private Sub Image1_Click()
MsgBox "Correct. This is an advisory road sign"
InsertPic "AdvisorySpeed.gif"
Me.Hide
End Sub
Private Sub Image2_Click()
MsgBox "Incorrect. This is a regulatory road sign"
InsertPic "DoNotEnter.gif"
Me.Hide
End Sub
Private Sub Image3_Click()
MsgBox "Incorrect. This is a regulatory road sign"
InsertPic "NoTurn.gif"
Me.Hide
End Sub
Private Sub Image4_Click()
MsgBox "Incorrect. This is a regulatory road sign"
InsertPic "OneWay.gif"
Me.Hide
End Sub

Sub InsertPic(ByRef pStr As String)
Dim oRng As Word.Range
Set oRng = ActiveDocument.Bookmarks("bmPPH").Range
oRng.Text = " "
oRng.InlineShapes.AddPicture FileName:= _
"C:\Documents and Settings\Maxey\Desktop\" & pStr, LinkToFile:=False, _
SaveWithDocument:=True
ActiveDocument.Bookmarks.Add "bmPPH", oRng
End Sub

This seems to work quite nicely, but the problem that I see is its
exportability to other users. It won't work unless other users have the
same images on their desktops. I am looking for suggestions that would make
this form exportable to other users. I thought about using AutoText but
then I would have to send the form and its template to other users. Another
idea I had was to insert all four images in the document and then use the
PictureFormat.Brightness attribute to show/hide the selected image in the
document. This seems clunky as I haven't sorted out how to make the
selected image appear in the right spot. I know that with Word2007 I could
put the images in the documetns OpenXML Format File datastore \images folder
and use some code to extract them to a temporary folder on then users
desktop, but I am looking for something that would work with Word2003.

Any ideas? Thanks.
 
G

Greg Maxey

Ok, I am making progress but still interested in other ideas.

Extending on the PictureFormat.Brightness idea I did the following.

I have a bookmark I use to display the selected response. Adjacent to that
bookmark I added for more bookmarks bmPic1 through bmPic4. I inserted one
of the four images into each of these bookmarks and then ran the following
code:

Sub MaskImages()
Dim i As Long
For i = 1 To 4
ActiveDocument.Bookmarks("bmPic" &
i).Range.InlineShapes(1).PictureFormat.Brightness = 0.99
Next i
End Sub

Now the images are in the document, masked, and fully exportable.

I revised the code in the userform as follows. When the user makes a
selection, the masked image is copied from the appropriate bookmark and then
pasted into the response bookmark and unmasked using the brightness
attribute.

Private Sub Image1_Click()
ShowResponse "bmPic1"
End Sub
Private Sub Image2_Click()
ShowResponse "bmPic2"
End Sub
Private Sub Image3_Click()
ShowResponse "bmPic3"
End Sub
Private Sub Image4_Click()
ShowResponse "bmPic4"
End Sub

Sub ShowResponse(ByRef pStr As String)
Dim oBMs As Bookmarks
Dim oRng As Word.Range
Set oBMs = ActiveDocument.Bookmarks
'Clear response placeholder bookmark
Set oRng = oBMs("bmPPH").Range
oRng.Text = " "
oBMs.Add "bmPPH", oRng
'Copy the selected masked image from its bookmarked range
oBMs(pStr).Range.Copy
'Paste the masked image in the response placeholder bookmark
Set oRng = oBMs("bmPPH").Range
oRng.Collapse wdCollapseStart
oRng.Paste
'Unmask and display the selected image
oBMs("bmPPH").Range.InlineShapes(1).PictureFormat.Brightness = 0.5
Me.Hide
End Sub
 

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