Results 1 to 3 of 3

How to alter a recorded macro to work better

Threaded View

antonymiller How to alter a recorded macro... 07-14-2009, 02:06 AM
antonymiller Solved 07-14-2009, 02:41 AM
royUK Re: How to alter a recorded... 07-14-2009, 02:53 AM
  1. #1
    Registered User
    Join Date
    07-07-2009
    Location
    Louisiana, United States
    MS-Off Ver
    Excel 2007
    Posts
    19

    Question How to alter a recorded macro to work better

    I have recorded the following macro to add a picture to the comment field for a cell. However, I notice that if I delete the initial comment and re-run the macro I get errors on every line of code.

    Why is that?

    How can this macro be altered so that I will give me the option to insert a picture no matter which cell I have selected?


    Sub AddPictureToCommentBox()
    '
    ' AddPictureToCommentBox Macro
    '
    Range("B18").Select
    Range("B18").AddComment
    Range("B18").Comment.Visible = False
    Range("B18").Comment.Text Text:="" & Chr(10) & ""
    Selection.ShapeRange.Fill.Transparency = 0#
    Selection.ShapeRange.Line.Weight = 0.75
    Selection.ShapeRange.Line.DashStyle = msoLineSolid
    Selection.ShapeRange.Line.Style = msoLineSingle
    Selection.ShapeRange.Line.Transparency = 0#
    Selection.ShapeRange.Line.Visible = msoTrue
    Selection.ShapeRange.Line.ForeColor.RGB = RGB(0, 0, 0)
    Selection.ShapeRange.Line.BackColor.RGB = RGB(255, 255, 255)
    Selection.ShapeRange.Fill.Visible = msoTrue
    Selection.ShapeRange.Fill.ForeColor.RGB = RGB(255, 255, 255)
    Selection.ShapeRange.Fill.BackColor.RGB = RGB(255, 255, 225)
    Selection.ShapeRange.Fill.UserPicture _
    "C:\Users\Tony\Pictures\Becca's Art\My Birthday Parrot b 4-16-09.png"

    ----------------------------------------------------------------------------------------------------

    I came across this macro which looks like it should do what I want but doesn't go any further than to add a comment box - there is no prompt to select an image. so essentially i'm left with an empty message box.

    Sub AddPictureToComment()
    Dim rng As Range
    Dim shp As Comment

    Set rng = ActiveCell

    If Not rng.Comment Is Nothing Then
    rng.Comment.Delete
    End If

    If rng.Text <> "" Then
    Set shp = rng.AddComment("")
    shp.Shape.Fill.UserPicture rng.Text

    End If

    End Sub
    Last edited by antonymiller; 07-14-2009 at 02:16 AM. Reason: Additional information

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