tjmck2
09-04-2017, 03:03 PM
My Dim Image1 As Range is wrong.... The code to upload the image to the form works. All the other codes work. I just can't get the image, once uploaded, to it's corresponding bookmark.
I'm attempting a simple VBA form in Microsoft Word where the UserForm1 pops up automatically, information is filled out in the UserForm1 (Name, Grade, Image of Student), then upon Submit the information goes to it's bookmarks.
Thank you in advance.
Private Sub CommandButton1_Click()
Dim FirstName As Range
Set FirstName = ActiveDocument.Bookmarks("FirstName").Range
FirstName.Text = Me.TextBox1.Value
Dim SurName As Range
Set SurName = ActiveDocument.Bookmarks("SurName").Range
SurName.Text = Me.TextBox2.Value
Dim Grade As Range
Set Grade = ActiveDocument.Bookmarks("Grade").Range
Grade.Text = Me.TextBox3.Value
Dim Image1 As Range
Set Image1 = ActiveDocument.Bookmarks("Image1").Range
Image1.Image1 = Me.Image1.Picture
Me.Repaint
UserForm1.Hide
End Sub
Private Sub CommandButton2_Click()
With Application.FileDialog(msoFileDialogFilePicker)
.AllowMultiSelect = False
.ButtonName = "Submit"
.Title = "Select an image file"
.Filters.Add "Image", "*.gif; *.jpg; *.jpeg", 1
If .Show = -1 Then
Me.Image1.PictureSizeMode = fmPictureSizeModeZoom
Me.Image1.Picture = LoadPicture(.SelectedItems(1))
Else
End If
End With
I'm attempting a simple VBA form in Microsoft Word where the UserForm1 pops up automatically, information is filled out in the UserForm1 (Name, Grade, Image of Student), then upon Submit the information goes to it's bookmarks.
Thank you in advance.
Private Sub CommandButton1_Click()
Dim FirstName As Range
Set FirstName = ActiveDocument.Bookmarks("FirstName").Range
FirstName.Text = Me.TextBox1.Value
Dim SurName As Range
Set SurName = ActiveDocument.Bookmarks("SurName").Range
SurName.Text = Me.TextBox2.Value
Dim Grade As Range
Set Grade = ActiveDocument.Bookmarks("Grade").Range
Grade.Text = Me.TextBox3.Value
Dim Image1 As Range
Set Image1 = ActiveDocument.Bookmarks("Image1").Range
Image1.Image1 = Me.Image1.Picture
Me.Repaint
UserForm1.Hide
End Sub
Private Sub CommandButton2_Click()
With Application.FileDialog(msoFileDialogFilePicker)
.AllowMultiSelect = False
.ButtonName = "Submit"
.Title = "Select an image file"
.Filters.Add "Image", "*.gif; *.jpg; *.jpeg", 1
If .Show = -1 Then
Me.Image1.PictureSizeMode = fmPictureSizeModeZoom
Me.Image1.Picture = LoadPicture(.SelectedItems(1))
Else
End If
End With