Hi All,
I have a problem with renaming and calling "Picture 1". I'm not a pro so bare with me...
I have the following code which calls a image from harddisk. After the image is loaded in a worksheet Excel set this name of the image to "Picture 1" This "Picture 1" is then copied and paste through VBA in the worksheet.
So suppose I want the name to be "IMAGEKLM" instead of "Picture 1"? How do I that?
I have the following code. Load image "2.jpg" from C drive and set the size and position:
Ok so far so good. Now I want to copy and paste this "Picture1" in the same worksheet with this line of code.
So the question is how can give this image"2.jpg" a name like "IMAGEKLM" so that the line of code would be
Any help would be appreciated, and thank you in advance...
Jim
I have a problem with renaming and calling "Picture 1". I'm not a pro so bare with me...
I have the following code which calls a image from harddisk. After the image is loaded in a worksheet Excel set this name of the image to "Picture 1" This "Picture 1" is then copied and paste through VBA in the worksheet.
So suppose I want the name to be "IMAGEKLM" instead of "Picture 1"? How do I that?
I have the following code. Load image "2.jpg" from C drive and set the size and position:
Sub TestInsertPictureInRange()
InsertPictureInRange "C:\1\2.jpg", _
Range("A1:D2")
End Sub
InsertPictureInRange "C:\1\2.jpg", _
Range("A1:D2")
End Sub
Sub InsertPictureInRange(PictureFileName As String, TargetCells As Range)
' inserts a picture and resizes it to fit the TargetCells range
Dim p As Object, t As Double, l As Double, w As Double, h As Double
If TypeName(ActiveSheet) <> "Worksheet" Then Exit Sub
If Dir(PictureFileName) = "" Then Exit Sub
' import picture
Set p = ActiveSheet.Pictures.Insert(PictureFileName)
If TypeName(ActiveSheet) <> "Worksheet" Then Exit Sub
If Dir(PictureFileName) = "" Then Exit Sub
' import picture
Set p = ActiveSheet.Pictures.Insert(PictureFileName)
' determine positions
With TargetCells
t = .Top
l = .Left
w = .Offset(0, .Columns.Count).Left - .Left
h = .Offset(.Rows.Count, 0).Top - .Top
End With
t = .Top
l = .Left
w = .Offset(0, .Columns.Count).Left - .Left
h = .Offset(.Rows.Count, 0).Top - .Top
End With
' position picture
With p
.Top = t
.Left = l
.Width = w
.Height = h
End With
Set p = Nothing
End Sub
.Top = t
.Left = l
.Width = w
.Height = h
End With
Set p = Nothing
End Sub
Ok so far so good. Now I want to copy and paste this "Picture1" in the same worksheet with this line of code.
Sub pasteImage()
ActiveSheet.Shapes.Range(Array("Picture 1")).Select
Selection.Copy
ActiveSheet.Paste
Selection.ShapeRange.IncrementLeft 412.5
Selection.ShapeRange.IncrementTop -12
Selection.ShapeRange.Height = 170.0787401575
Selection.ShapeRange.Width = 170.0787401575
Selection.ShapeRange.Rotation = 90
End Sub
ActiveSheet.Shapes.Range(Array("Picture 1")).Select
Selection.Copy
ActiveSheet.Paste
Selection.ShapeRange.IncrementLeft 412.5
Selection.ShapeRange.IncrementTop -12
Selection.ShapeRange.Height = 170.0787401575
Selection.ShapeRange.Width = 170.0787401575
Selection.ShapeRange.Rotation = 90
End Sub
So the question is how can give this image"2.jpg" a name like "IMAGEKLM" so that the line of code would be
ActiveSheet.Shapes.Range(Array("IMAGEKLM")).Select ??
Any help would be appreciated, and thank you in advance...
Jim