Consulting

Results 1 to 5 of 5

Thread: Solved: Insert comment pictures fill down.

  1. #1
    VBAX Expert Shazam's Avatar
    Joined
    Sep 2005
    Posts
    530
    Location

    Solved: Insert comment pictures fill down.

    Hi everyone,



    I'm trying to modify this code so it will insert comment with pictures in column A. Here what I got so far:

    I left an example file below.

    This where I originaly got the code from.

    http://www.vbaexpress.com/forum/showthread.php?t=8789


    [vba]Sub pix()


    Dim rngCell As Range
    Dim curWks As Worksheet
    Dim c As Object
    Dim Path As String



    Set curWks = ActiveSheet


    Path = "C:\" & Range("A2:a" & Cells(Rows.Count, "A").End(xlUp).Row).Text & ".jpg"


    With rngCell.Offset(0, 0)
    .AddComment("").Shape.Fill.UserPicture (Path)
    For Each c In ActiveSheet.Comments
    c.Shape.Width = 400
    c.Shape.Height = 300
    Next c
    End With


    End Sub[/vba]
    Last edited by Shazam; 05-10-2008 at 03:36 PM.
    SHAZAM!

  2. #2
    Moderator VBAX Guru Simon Lloyd's Avatar
    Joined
    Sep 2005
    Location
    UK
    Posts
    3,003
    Location
    Why insert a comment, you could use data validation like this:
    [VBA]
    With Range("A1").Validation
    .Delete
    .Add Type:=xlValidateInputOnly, AlertStyle:=xlValidAlertStop, Operator _
    :=xlBetween
    .InputMessage = "You have a picture in this cell!"
    End With
    [/VBA]this shows no dropdown, doesn't require an input just shows a "comment" when the cell is selected!
    Regards,
    Simon
    Please read this before cross posting!
    In the unlikely event you didn't get your answer here try Microsoft Office Discussion @ The Code Cage
    If I have seen further it is by standing on the shoulders of giants.
    Isaac Newton, Letter to Robert Hooke, February 5, 1675 English mathematician & physicist (1642 - 1727)

  3. #3
    VBAX Expert Shazam's Avatar
    Joined
    Sep 2005
    Posts
    530
    Location
    Sorrry Simon Lloyd



    That won't work I need it the way I have in the example file I posted.


    Any help?
    SHAZAM!

  4. #4
    VBAX Expert
    Joined
    Feb 2005
    Location
    Nanaimo, British Columbia, Cananda
    Posts
    568
    Location
    Hi Shazam,

    This should help you out.

    [VBA]
    Option Explicit
    Sub Mypix()

    Dim c As Object
    Dim eMsg As String
    Dim Pathe As String
    Dim rngCell As Range
    Dim rngSheet As Range
    Dim curWks As Worksheet

    'Handle errors
    On Error GoTo endo

    'Speed
    Application.ScreenUpdating = False

    'Create reference
    Set curWks = ActiveSheet

    'Employ reference
    With curWks
    'Clear all old comments
    .Columns("A").ClearComments
    'Define range as Col A1 to last row Col A
    Set rngSheet = .Range("A1:A" & Cells(Rows.Count, "A").End(xlUp).Row)
    End With

    'Drive (& optionally directory) must end with "\"
    Pathe = "L:\"

    'For each cell
    For Each rngCell In rngSheet
    'If blank
    If Trim(rngCell.Value) = "" Then
    'do nothing
    ElseIf Dir(Pathe & rngCell.Value & ".jpg") = "" Then
    'picture not there!
    MsgBox rngCell.Value & " doesn't exist!"
    Else
    'put picture
    rngCell.AddComment("").Shape.Fill.UserPicture (Pathe & rngCell.Value & ".jpg")
    End If
    Next rngCell

    'Set size for all pictures
    For Each c In ActiveSheet.Comments
    c.Shape.Width = 400
    c.Shape.Height = 300
    Next c

    'Destroy reference\
    Set c = Nothing
    Set curWks = Nothing
    Set rngCell = Nothing
    Set rngSheet = Nothing

    'Reset
    Application.ScreenUpdating = True

    'Normal exit
    Exit Sub
    'Errored out
    endo:
    'Destroy reference\
    Set c = Nothing
    Set curWks = Nothing
    Set rngCell = Nothing
    Set rngSheet = Nothing

    'Reset
    Application.ScreenUpdating = True

    eMsg = MsgBox("Error number: " & Err.Number & " " & Err.Description, vbCritical)
    End Sub

    [/VBA]
    Cheers,

    dr

    "Questions, help and advice for free, small projects by donation. large projects by quote"

    http:\\www.ExcelVBA.joellerabu.com

  5. #5
    VBAX Expert Shazam's Avatar
    Joined
    Sep 2005
    Posts
    530
    Location
    Well done rbrhodes the code is perfect.


    Thank you so much!
    SHAZAM!

Posting Permissions

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