Hello,
I need help modifying this VBA code. I currently have a button command in the middle of the square, and anytime I push it, select my picture to use it throws it on a different page. What do I need to modify in order to have it drop the picture into the square that the command button resides in?
I need help modifying this VBA code. I currently have a button command in the middle of the square, and anytime I push it, select my picture to use it throws it on a different page. What do I need to modify in order to have it drop the picture into the square that the command button resides in?
Book1 | ||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
A | B | C | D | E | F | G | H | I | J | K | L | |||
1 | ||||||||||||||
2 | ||||||||||||||
3 | Images | |||||||||||||
4 | ||||||||||||||
5 | ||||||||||||||
6 | ||||||||||||||
7 | ||||||||||||||
8 | ||||||||||||||
9 | ||||||||||||||
10 | ||||||||||||||
11 | ||||||||||||||
12 | ||||||||||||||
13 | ||||||||||||||
14 | ||||||||||||||
15 | ||||||||||||||
16 | ||||||||||||||
17 | ||||||||||||||
18 | ||||||||||||||
19 | ||||||||||||||
20 | ||||||||||||||
21 | ||||||||||||||
22 | ||||||||||||||
23 | ||||||||||||||
24 | ||||||||||||||
25 | ||||||||||||||
26 | ||||||||||||||
27 | ||||||||||||||
Images |
VBA Code:
Sub CommandButton1_Click()
Dim strFileName As String
Dim objPic As Picture
Dim rngDest As Range
strFileName = Application.GetOpenFilename( _
FileFilter:="Images (*.jpg;*.gif;*.png),*.jpg;*.gif;*.png", _
Title:="Please select an image...")
If strFileName = "False" Then Exit Sub
Set rngDest = Worksheets("Images").Range("B10:F17")
Set objPic = Worksheets("Images").Pictures.Insert(strFileName)
With objPic
.ShapeRange.LockAspectRatio = msoTrue
.Left = rngDest.Left
.Top = rngDest.Top
.Width = rngDest.Width
.Height = rngDest.Height
End With
End Sub