Consulting

Results 1 to 7 of 7

Thread: Solved: Insert .JPEG

  1. #1
    VBAX Regular
    Joined
    Oct 2010
    Location
    Texas
    Posts
    93
    Location

    Smile Solved: Insert .JPEG

    Hello Everyone,

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

    [VBA]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[/VBA]

    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!!!

  2. #2
    VBAX Guru Kenneth Hobs's Avatar
    Joined
    Nov 2005
    Location
    Tecumseh, OK
    Posts
    4,956
    Location
    [VBA]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[/VBA]

  3. #3
    VBAX Regular
    Joined
    Mar 2010
    Posts
    49
    Location
    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

  4. #4
    VBAX Guru Kenneth Hobs's Avatar
    Joined
    Nov 2005
    Location
    Tecumseh, OK
    Posts
    4,956
    Location
    Change Range("B5") to ActiveCell.

  5. #5
    VBAX Regular
    Joined
    Oct 2010
    Location
    Texas
    Posts
    93
    Location
    Thank you for your help!!

  6. #6
    VBAX Regular
    Joined
    Oct 2010
    Location
    Texas
    Posts
    93
    Location
    Thank you very much!!

  7. #7
    VBAX Regular
    Joined
    Mar 2010
    Posts
    49
    Location
    Many thanks for a nice share

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •