+ Reply to Thread
Results 1 to 5 of 5

Macro: Insert Comment with Picture

Hybrid View

  1. #1
    Registered User
    Join Date
    12-03-2006
    Posts
    15

    Macro: Insert Comment with Picture

    Hi,

    I've recently created a spreadsheet with the aim of recording errors in a product.

    The easiest way to show these errors is sometimes with a picture and here is the problem. When I use autofilter the pictures do not get filtered. I would therefore like to add the pictures as a comment instead however do not want to go through the long process of clicking all the boxes each time. Idealy I don't want to collect the image from a separate file but would like to paste it directly into a comment.

    I have tried various ways of recording Macro's but have had no success.

    I have also found the below code after various searches but I don't have a great enough understanding to minipulate it.

    Can any one help me?

    Thank you,

    Stephen
    Sub PictureIntoComment()
    'www.contextures.com\xlcomments03.html
    Dim ch As ChartObject
    Dim dWidth As Double
    Dim dHeight As Double
    Dim ws As Worksheet
    Dim sName As String
    Dim cmt As Comment
    Dim sPath As String
    Dim sFile As String
    Dim rng As Range
    Set ws = ActiveSheet
    Set rng = ActiveCell
    sPath = ThisWorkbook.Path & "\"
    sName = InputBox("Name for picture file (no extension)", "File Name")
    If sName = "" Then sName = "Picture_" & Format(Date, "yyyymmdd")
    sFile = sPath & sName & ".gif"
     
        dWidth = Selection.Width
        dHeight = Selection.Height
     
        Selection.Cut
        Set ch = ws.ChartObjects.Add(Left:=rng.Left, Top:=rng.Top, _
          Width:=dWidth, Height:=dHeight)
        ch.Chart.Paste
        rng.Activate
        ch.Chart.Export sFile
        ch.Delete
        Set cmt = rng.AddComment
        cmt.Text Text:=""
        With cmt.Shape
          .Fill.UserPicture sFile
          .Width = dWidth
          .Height = dHeight
        End With
     
    End Sub

  2. #2
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    22,001

    Re: Macro: Insert Comment with Picture

    That code is for exporting images, not inserting them. What exactly did you mean by:
    Idealy I don't want to collect the image from a separate file but would like to paste it directly into a comment
    Where would the macro come in and where are you copying the pictures from?

    Cross-posted here.
    Last edited by romperstomper; 06-24-2009 at 11:25 AM.
    Everyone who confuses correlation and causation ends up dead.

  3. #3
    Registered User
    Join Date
    12-03-2006
    Posts
    15

    Re: Macro: Insert Comment with Picture

    Hi romperstomper,

    Thanks for the quick response,

    I would like the macro to be run on a selected cell with a coommand button. The picture will come from a CAD model as a print screen, so i don't want to have to then save this a seperate file to insert later, idealy the print screen can be pasted directly into the comment.

    Thanks,

    Stephen

  4. #4
    Registered User
    Join Date
    12-03-2006
    Posts
    15

    Re: Macro: Insert Comment with Picture

    Problem solved here: http://www.mrexcel.com/forum/showthr...=1#post1978712

    altough I would still be interestreed in the above solution as it offers a much more user friendly view.

    Thanks,

    Stephen

  5. #5
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    22,001

    Re: Macro: Insert Comment with Picture

    I think you would have to write the image to a disk file and load from there; I don't know of a way to paste one in

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1