I'm trying to get a picture to snap into a specific range but for some reason when i copy and paste the code again and change the range it keep getting an error highlighted in yellow, even though it identical besides the range location. what am I doing wrong?
Private Sub CommandButton2_Click()
Dim strFileName As String
Dim objPic As Picture
Dim rngDest As Range
strFileName = Application.GetOpenFilename( _
FileFilter:="Images (*.jpg;*.gif;*.png;*.bmp),*.jpg;*.gif;*.png;*.bmp", _
Title:="Please select an image...")
If strFileName = "False" Then Exit Sub
Set rngDest = Range("B3:H39") 'This line sets the ActiveCell as the Target for insertion of the picture
Set objPic2 = Worksheets("pic 2").Pictures.Insert(strFileName)
With objPic
.ShapeRange.LockAspectRatio = msoFalse 'This line locks the ratio of Width to Height if =msoTrue, no distortion
.Left = rngDest.Left 'The ' .Left=' and ' .Top=' in this and the next line set the respective locations for the placement of the picture
.Top = rngDest.Top
.Width = rngDest.Width 'You can put an single quote before this line if you want to hold just the Height of the picture to be the height of the cell where it will be placed
.Height = rngDest.Height 'You can put an single quote before this line if you want to hold just the Width of the picture to be the width of the cell where it will be placed
End With
End Sub
Private Sub CommandButton3_Click()
Dim strFileName As String
Dim objPic As Picture
Dim rngDest As Range
strFileName = Application.GetOpenFilename( _
FileFilter:="Images (*.jpg;*.gif;*.png;*.bmp),*.jpg;*.gif;*.png;*.bmp", _
Title:="Please select an image...")
If strFileName = "False" Then Exit Sub
Set rngDest = Range("K3:Q39") 'This line sets the ActiveCell as the Target for insertion of the picture
Set objPic2 = Worksheets("pic 2").Pictures.Insert(strFileName)
Set objPic2 = Worksheets("pic 2").Pictures.Insert(strFileName)
With objPic
.ShapeRange.LockAspectRatio = msoFalse 'This line locks the ratio of Width to Height if =msoTrue, no distortion
.Left = rngDest.Left 'The ' .Left=' and ' .Top=' in this and the next line set the respective locations for the placement of the picture
.Top = rngDest.Top
.Width = rngDest.Width 'You can put an single quote before this line if you want to hold just the Height of the picture to be the height of the cell where it will be placed
.Height = rngDest.Height 'You can put an single quote before this line if you want to hold just the Width of the picture to be the width of the cell where it will be placed
End With
End Sub
Private Sub CommandButton2_Click()
Dim strFileName As String
Dim objPic As Picture
Dim rngDest As Range
strFileName = Application.GetOpenFilename( _
FileFilter:="Images (*.jpg;*.gif;*.png;*.bmp),*.jpg;*.gif;*.png;*.bmp", _
Title:="Please select an image...")
If strFileName = "False" Then Exit Sub
Set rngDest = Range("B3:H39") 'This line sets the ActiveCell as the Target for insertion of the picture
Set objPic2 = Worksheets("pic 2").Pictures.Insert(strFileName)
With objPic
.ShapeRange.LockAspectRatio = msoFalse 'This line locks the ratio of Width to Height if =msoTrue, no distortion
.Left = rngDest.Left 'The ' .Left=' and ' .Top=' in this and the next line set the respective locations for the placement of the picture
.Top = rngDest.Top
.Width = rngDest.Width 'You can put an single quote before this line if you want to hold just the Height of the picture to be the height of the cell where it will be placed
.Height = rngDest.Height 'You can put an single quote before this line if you want to hold just the Width of the picture to be the width of the cell where it will be placed
End With
End Sub
Private Sub CommandButton3_Click()
Dim strFileName As String
Dim objPic As Picture
Dim rngDest As Range
strFileName = Application.GetOpenFilename( _
FileFilter:="Images (*.jpg;*.gif;*.png;*.bmp),*.jpg;*.gif;*.png;*.bmp", _
Title:="Please select an image...")
If strFileName = "False" Then Exit Sub
Set rngDest = Range("K3:Q39") 'This line sets the ActiveCell as the Target for insertion of the picture
Set objPic2 = Worksheets("pic 2").Pictures.Insert(strFileName)
Set objPic2 = Worksheets("pic 2").Pictures.Insert(strFileName)
With objPic
.ShapeRange.LockAspectRatio = msoFalse 'This line locks the ratio of Width to Height if =msoTrue, no distortion
.Left = rngDest.Left 'The ' .Left=' and ' .Top=' in this and the next line set the respective locations for the placement of the picture
.Top = rngDest.Top
.Width = rngDest.Width 'You can put an single quote before this line if you want to hold just the Height of the picture to be the height of the cell where it will be placed
.Height = rngDest.Height 'You can put an single quote before this line if you want to hold just the Width of the picture to be the width of the cell where it will be placed
End With
End Sub