+ Reply to Thread
Results 1 to 2 of 2

Macro to enter a shape with text and macro

Hybrid View

  1. #1
    Registered User
    Join Date
    12-21-2007
    Posts
    20

    Macro to enter a shape with text and macro

    I am trying to create a tutorial sheet for a workbook that I am putting together. The goal is to add a comment shape with rounded corners, light blue, with text in the box, with a macro attached and I need to delete a previous comment shape (thats the extra macro attached). I have been trying to get this to work all morning by just recording a macro but cant seem to figure it out. If anyone has any suggestions they would be greatly appriciated.
    Thanks

  2. #2
    Forum Expert
    Join Date
    01-15-2007
    Location
    Brisbane, Australia
    MS-Off Ver
    2007
    Posts
    6,591
    Hi

    When you create the shape, give it a name. That way the macro can look for the shape specifically and delete it. The code below should give you the idea. The shape etc was just the first thing I grabbed to give you the idea.

    On Error Resume Next
      Set oldone = ActiveSheet.Shapes("fred")
      On Error GoTo 0
      If Not IsEmpty(oldone) Then oldone.Delete
      
        ActiveSheet.Shapes.AddShape(msoShapeOval, 142.5, 42#, 95.25, 36.75).Select
        Selection.Name = "fred"
        Selection.Characters.Text = "This is a test."
        With Selection.Characters(Start:=1, Length:=15).Font
            .Name = "Arial"
            .FontStyle = "Regular"
            .Size = 10
            .Strikethrough = False
            .Superscript = False
            .Subscript = False
            .OutlineFont = False
            .Shadow = False
            .Underline = xlUnderlineStyleNone
            .ColorIndex = xlAutomatic
        End With
        Range("A1").Select
    rylo

+ 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