PDA

View Full Version : Populate and Activex image control by FileDialog (code)



Subguy702
03-10-2014, 04:44 PM
I am trying to populate an Activex image control on a Word document, but can't seem to seal the deal. using this code:
_____
Private Sub Image2_Click()

Dim pd As FileDialog

Set pd = Application.FileDialog(msoFileDialogFilePicker)

Dim ImgPck As Variant

With pd
.Filters.Clear
.Filters.Add "Image", "*.jpg", 1
.InitialFileName = "C:\"

If .Show = -1 Then

Image2.Picture = "'" & ImgPck & "'"

Else
End If

End With

Set pd = Nothing
End Sub

As you can see, I can get it to open the file picker, but lack the knowledge to make the Image2 (Image Control) show the image. I keep getting the "object required" error statement.

I'm very new to this, and would appreciate any help I can get. (Hope it's simple, I tend to over-think these things)

Thanks!

ps I just realized I didn't define ImgPck as anything. I tried to equate it to .SelectedItems, but keep getting a Type Mismatch. Oh well...

gmaxey
03-10-2014, 06:10 PM
Private Sub Image2_Click()
Dim oFD As FileDialog
Set oFD = Application.FileDialog(msoFileDialogFilePicker)
With oFD
.Filters.Clear
.Filters.Add "Image", "*.jpg", 1
.InitialFileName = "C:\"
If .Show = -1 Then
Image2.Picture = LoadPicture(.SelectedItems.Item(1))
End If
End With
End Sub

Subguy702
03-11-2014, 07:34 AM
Thank you, Mr. Maxey. Simple and elegant; just what I was hoping for!