Consulting

Results 1 to 6 of 6

Thread: path string in cell

  1. #1

    path string in cell

    i have folder which contain the "jpg" images. i have table wiuth three fields.

    ID Autonumber
    Pictname text ---255
    Picpath Text--255

    Recrods /Data in table
    ID = 1
    Picname Red
    PicPath 'f:\cards\desktop\red.jpg'
    ID = 2
    Picname blue
    PicPath 'f:\cards\desktop\blue.jpg' or "f:\cards\desktop\blue.jpg"

    but when i call/retrive this picure in image box it is showing f:\cards\desktop\blue.jpg not the picture. wether i have tried to store this path in this format also. but not succesed. "
    please advised.

  2. #2
    VBAX Guru mancubus's Avatar
    Joined
    Dec 2010
    Location
    "Where I lay my head is home" :D
    Posts
    2,644
    post your workbook as explained in my signature.
    PLS DO NOT PM; OPEN A THREAD INSTEAD!!!

    1) Posting Code
    [CODE]PasteYourCodeHere[/CODE]
    (or paste your code, select it, click # button)

    2) Uploading File(s)
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) (multiple files can be selected while holding Ctrl key) / Upload Files / Done
    Replace company specific / sensitive / confidential data. Include so many rows and sheets etc in the uploaded workbook to enable the helpers visualize the data and table structure. Helpers do not need the entire workbook.

    3) Testing the Codes
    always back up your files before testing the codes.

    4) Marking the Thread as Solved
    from Thread Tools (on the top right corner, above the first message)

  3. #3

    re path as string

    please view the attached file
    Attached Files Attached Files

  4. #4
    VBAX Guru Kenneth Hobs's Avatar
    Joined
    Nov 2005
    Location
    Tecumseh, OK
    Posts
    4,956
    Location
    How are you calling or retrieving pictures? If by code, please click the # icon and paste between codes.

    If done manually, I suspect that blue.jpg is not an actual jpg file.

  5. #5
    Dim picname As String
     
    Range("B1").Select  'This is where picture will be inserted 
     
    picname = Range("A1")  'This is the picture name 
     
    On Error Resume Next
      'delete previous pic 
    ActiveSheet.Pictures("ProfilePicture").Delete
    Err.Clear
    Err.Number = 0
    On Error GoTo 0
     
    If (Dir("C:\Users\JINOOB\Desktop\I A\" & picname & ".jpg") = vbNullString) Then Exit Sub
     
    ActiveSheet.Pictures.Insert("C:\Users\JINOOB\Desktop\I A\" & picname & ".jpg").Select  'Path to where pictures are stored 
      ''''''''''''''''''''''''''''''''''''''''''''''''''''''' 
      ' This resizes the picture 
      ''''''''''''''''''''''''''''''''''''''''''''''''''''''' 
    With Selection
        .Name = "ProfilePicture"
        .Left = Range("B1").Left
        .Top = Range("B1").Top
        .ShapeRange.LockAspectRatio = msoFalse
        .ShapeRange.Height = 95#
        .ShapeRange.Width = 80#
        .ShapeRange.Rotation = 0#
    End With
    End Sub
    Last edited by SamT; 01-24-2017 at 09:52 PM. Reason: Removed color tags

  6. #6
    VBAX Guru Kenneth Hobs's Avatar
    Joined
    Nov 2005
    Location
    Tecumseh, OK
    Posts
    4,956
    Location
    Your code only deals with one pic. Pictures.Insert() insert links to pics.

    I used Shapes.AddPicture() to embed the pics though it can link pics too. Put this in a Module and call as you like. Use whichever Set s that you like best.
    Sub Main()    
      Dim c As Range, r As Range, p As Range
      Dim s As Shape, fn$
      
      On Error Resume Next
      Set r = Range("B2", Cells(Rows.Count, "B").End(xlUp))
      For Each c In r
        Set p = c.Offset(, 2) 'Column D
        fn = c.Offset(, 1)  'Column C value
        Set s = ActiveSheet.Shapes.AddPicture _
          (fn, msoFalse, msoTrue, _
            p.Left, p.Top, 80, 95) 'embed files
        'Set s = ActiveSheet.Shapes.AddPicture _
          (fn, msoFalse, msoTrue, _
            p.Left, p.Top, p.Width, p.RowHeight) 'embed files
        s.LockAspectRatio = False
        s.Name = c
      Next c
    End Sub

Posting Permissions

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