PDA

View Full Version : Solved: Insert .JPEG



chem101
10-14-2010, 02:03 PM
Hello Everyone,

I have a worksheet using the following code to retrieve a .jpeg and insert on to the worksheet:

Sub InsertDCPic()

Dim vFilename As Variant
Dim sPath As String
sPath = "c:\"
ChDrive sPath
ChDir sPath
vFilename = Application.GetOpenFilename("picture files (*.jpg),*.jpg", , "Please Select Die Cut Picture To Place On Warehouse Master", , False)
If TypeName(vFilename) = "Boolean" Then Exit Sub
If CStr(vFilename) = "" Then Exit Sub
If Dir(CStr(vFilename)) <> "" Then
ActiveSheet.Pictures.Insert CStr(vFilename)

End If
End Sub

Is it possible to use VBA code to insert the .jpeg into a specific cell range automatically? If so can this be done if this cell range is unlocked and the rest of the worksheet is protected?

Thank you in advance for any assistance you can provide!!!

Kenneth Hobs
10-14-2010, 06:29 PM
Sub InsertDCPic()
Dim vFilename As Variant
Dim sPath As String
Dim s As Shape, r As Range
sPath = "c:\"
ChDrive sPath
ChDir sPath
vFilename = Application.GetOpenFilename("picture files (*.jpg),*.jpg", , "Please Select Die Cut Picture To Place On Warehouse Master", , False)
If TypeName(vFilename) = "Boolean" Then Exit Sub
If CStr(vFilename) = "" Then Exit Sub
If Dir(CStr(vFilename)) <> "" Then
'Set pic = LoadPicture(CStr(vFilename))
Set r = Range("B5")
Set s = ActiveSheet.Shapes.AddPicture(CStr(vFilename), msoFalse, msoTrue, r.Left, r.Top, 36, 36)
s.TopLeftCell = Range("B5")
End If
End Sub

softman
10-14-2010, 11:39 PM
Dear Kenneth,

I like the way it work but wonder if it's possible to place the picture where the cursor is and then insart the pic there to make it possible to upload more pictures and not only one cell as "B5"

Many thanks

Kenneth Hobs
10-15-2010, 05:29 AM
Change Range("B5") to ActiveCell.

chem101
10-15-2010, 05:31 AM
Thank you for your help!!

chem101
10-15-2010, 05:53 AM
Thank you very much!!

softman
10-18-2010, 12:45 AM
Many thanks for a nice share