Loading
Ozgrid Excel Help & Best Practices Forums

Excel Video Tutorials / Excel Dashboards Reports



Results 1 to 3 of 3

Thread: Adding Cell Comments with VBA

  1. #1
    Join Date
    19th September 2004
    Location
    Chester
    Posts
    148

    Adding Cell Comments with VBA

    Hi all,

    I'm currently playing with the following.............

    VB:
    Public comment_test() 
     
    Dim unme As String 
    Dim com As String 
    unme = Application.UserName 
    com = InputBox("comment....") 
     
    ActiveCell.AddComment (unme & " " & com) 
     
    End Sub 
    
    

    I have noticed that if you add comments with VBA it does not place the username at the start in bold automaticaly (thats why i have added it myself) is there a quick fix for this and how do i perform a carridge return inside a coment using code?

    in advance

    Excel Video Tutorials / Excel Dashboards Reports


  2. #2
    Join Date
    7th March 2003
    Location
    Essex, England
    Posts
    11,313

    Re: Adding Cell Comments with VBA

    Hi,

    If you record a macro whilst adding comments you will see that the username is added rather than appearing by default. So you have to do the same.
    This will add the header text in bold and then append what extra text is specified.
    VB:
    Sub Test() 
        MyAddComment Range("A1"),"Hello World" 
    End Sub 
     
    Sub MyAddComment(ToCell As Range, Text As String) 
         
        Dim objComment As Comment 
        Dim strHeader As String 
         
        With ToCell 
            strHeader = Application.UserName & ":" & vbLf 
            Set objComment = .AddComment(strHeader & Text) 
            With objComment.Shape.TextFrame 
                .Characters.Font.Bold = False 
                .Characters(1, Len(strHeader)).Font.Bold = True 
            End With 
        End With 
         
    End Sub 
    
    

    Cheers
    Andy


  3. #3
    Join Date
    19th September 2004
    Location
    Chester
    Posts
    148

    Re: Adding Cell Comments with VBA

    Cheers Andy!

    Excel Video Tutorials / Excel Dashboards Reports


Thread Information

Users Browsing this Thread

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

Possible Answers

  1. Adding Comments To A Range
    By ftm in forum EXCEL HELP
    Replies: 2
    Last Post: April 27th, 2007, 01:00
  2. Adding Comments To Formulas
    By Dave Hawley in forum OPEN SOURCE: Hey! That is Cool!
    Replies: 1
    Last Post: March 28th, 2007, 06:21
  3. Adding Comments To Many Rows In Vba
    By jonny in forum EXCEL HELP
    Replies: 3
    Last Post: February 15th, 2007, 17:09
  4. 2 comments in 1 cell
    By nganesh.kumar in forum EXCEL HELP
    Replies: 1
    Last Post: March 29th, 2005, 14:41
  5. cell comments
    By imported_Anonymous in forum EXCEL HELP
    Replies: 2
    Last Post: February 18th, 2003, 03:11

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
  •  
porno