Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

XL2000: How to use a Macro to Enter Cell Note Text in a Text Box


View products that this article applies to.

This article was previously published under Q213623

↑ Back to the top


Summary

This article describes how to put the text of a cell's comment (cell note) into a text box. A macro that does this may be especially helpful because you do not have the ability to manually copy text from the comment dialog box and paste it into a text box.

↑ Back to the top


More information

Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements. The following sample macro creates a text box and fills it with the text from a comment.

Sample Visual Basic Procedure

Sub GetCellNote()
       Dim Box As Object, X As Integer
       ' Check to see if there is a Comment in the Active Cell.
       If ActiveCell.Comment Is Nothing Then
            MsgBox "There is not a note in the Active Cell.", vbExclamation
            Exit Sub
       End If
       ' Add a text box and position it to the right of the active cell.
       Set Box = ActiveSheet.TextBoxes.Add(ActiveCell.Offset(1, 1).Left, _
           ActiveCell.Offset(1, 1).Top, ActiveCell.Offset(1, 3).Left, _
           ActiveCell.Offset(6, 1).Top)
       ' Use the NoteText method to add text to the Comment - See 
       ' 'NoteText Method' in Excel Help.
       ' We can only get 255 Characters at a time; so, loop until all of
       ' the Comment text is retrieved.
       Do Until Len(ActiveCell.NoteText(Start:=X * 255 + 1)) = 0
           Box.Characters(X * 255 + 1).Text = _
               ActiveCell.NoteText(Start:=X * 255 + 1)
           X = X + 1 ' get the next 255 characters
       Loop
End Sub
   
				
To use the preceding macro in Excel, point to Macro on the Tools menu, and then click Macros. Click the GetCellNote macro, and then click Run. If necessary, size the text box such that you can view the entire note.

↑ Back to the top


Keywords: KB213623, kbprogramming, kbhowto, kbdtacode

↑ Back to the top

Article Info
Article ID : 213623
Revision : 6
Created on : 10/10/2006
Published on : 10/10/2006
Exists online : False
Views : 244