+ Reply to Thread
Results 1 to 3 of 3

Autosize a comment

Hybrid View

gtmeloney Autosize a comment 06-03-2009, 03:51 PM
gtmeloney Re: Autosize a comment 06-03-2009, 04:22 PM
Leith Ross Re: Autosize a comment 06-03-2009, 04:30 PM
  1. #1
    Registered User
    Join Date
    05-05-2009
    Location
    San Diego, CA
    MS-Off Ver
    Excel 2003
    Posts
    97

    Autosize a comment

    my macro processes a lot of data and puts a comment in certain cells (several thousand of them). I would like to autosize the comments so that the text can all be read by default.

    I found the following on the web:
        
    With Worksheets("Budget").Range("A1").AddComment
            .Text x
            .Visible = True
            .Shape.AutoShapeType = msoShapeRoundedRectangle
        End With
        
        Worksheets("Budget").Range("A1").Comment.Shape.Select True
    
       With Selection
            .AutoSize = True
        End With
    My problem is that this requires the cell with the comment in it to be active AND VISIBLE. Is there any way that I can apply the autosize without having the cell VISIBLE?

    The reason is that I have 2 worksheets that have comments on them, and I don't want to continually flicker between them activating cells
    Last edited by gtmeloney; 06-03-2009 at 04:22 PM.

  2. #2
    Registered User
    Join Date
    05-05-2009
    Location
    San Diego, CA
    MS-Off Ver
    Excel 2003
    Posts
    97

    Re: Autosize a comment

    Found it.

       
     For Each x In Worksheets("Budget By Month").Comments
            With x.Shape.TextFrame
                .AutoSize = True
            End With
        Next x
    does the trick quickly without having to activate each cell individually.

  3. #3
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Autosize a comment

    Hello gtmeloney,

    Here ia macro that will auto size the comment. If the cell doesn't contain a comment then one is added, otherwise the text is replaced.
    Sub CommnetTest()
    
      Dim Cmnt As Comment
      Dim Rng As Range
      Dim Txt As String
      
        Txt = "Comment test text."
        
        Set Rng = Worksheets("Sheet1").Range("A1")
        Set Cmnt = Rng.Comment
        
       'Check if cell has a comment
        If Cmnt Is Nothing Then
           Rng.AddComment Txt
           Set Cmnt = Rng.Comment
        End If
        
        With Cmnt
          .Text Txt
          .Shape.AutoShapeType = msoShapeRoundedRectangle
          .Shape.TextFrame.Characters.Text = ""
          .Shape.TextFrame.AutoSize = True
          .Shape.TextFrame.Characters.Text = Txt
        End With
        
    End Sub
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

+ 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