gabethegrape
New Member
- Joined
- Mar 3, 2009
- Messages
- 38
In my Excel 2007 doc, I have the following code which works perfectly for inserting image from a local folder. I now have this other code for inserting images from a URL which only partially does what I need. If it's possible, I'd like the user to copy the URL for the image and when they press a command button, insert that image into the specified cell (similar to the first code). Here are the codes that I have so far:
For inserting from local folder:
and for the URL image:
For inserting from local folder:
Code:
Sub InsertPicture1()
Dim myPicture As String
Dim pic As Picture
myPicture = Application.GetOpenFilename _
("Pictures (*.gif; *.jpg; *.bmp; *.tif),*.gif; *.jpg; *.bmp; *.tif", , "Select Picture to Import")
If myPicture = "False" Then Exit Sub
If myPicture <> "" Then
Set r = Range("b10")
Set pic = ActiveSheet.Pictures.Insert(myPicture)
If pic.Height > pic.Width Then
With pic
.Top = r.Top
.Left = r.Left
.ShapeRange.LockAspectRatio = msoCTrue
.Height = 206
.Placement = xlMoveAndSize
End With
ElseIf pic.Width > pic.Height Then
With pic
.Top = r.Top
.Left = r.Left
.ShapeRange.LockAspectRatio = msoCTrue
.Width = 208
.Placement = xlMoveAndSize
End With
ElseIf pic.Height = pic.Width Then
With pic
.Top = r.Top
.Left = r.Left
.ShapeRange.LockAspectRatio = msoCTrue
.Width = 208
.Placement = xlMoveAndSize
End With
End If
End If
End Sub
Code:
Sub InsertPicture()
Dim myPicture As Shape
Set myPicture = ActiveSheet.Shapes.AddShape(msoShapeRectangle, 2, 2, 200, 200)
myPicture.Fill.UserPicture "http://www.google.com/intl/en_ALL/images/logo.gif"
End Sub