Академический Документы
Профессиональный Документы
Культура Документы
Sub CommentAddOrEdit()
'adds new plain text comment or positions
'cursor at end of existing comment text
'www.contextures.com\xlcomments03.html
Dim cmt As Comment
Set cmt = ActiveCell.Comment
If cmt Is Nothing Then
ActiveCell.AddComment text :=""
End If
SendKeys "%ie~"
End Sub
To avoid use of the SendKeys command, you can use the following
variation , which leaves the Excel comments visible. After running
the macro, the comment shape is selected. Start typing, and the
text will be added to the comment box, or to the end of the existing
comment text.
Sub CommentAddOrEdit()
'method suggested by Jon Peltier 2006-03-04
'adds new plain text comment or adds text
'at end of existing comment text
Dim cmt As Comment
Set cmt = ActiveCell.Comment
If cmt Is Nothing Then
Set cmt = ActiveCell.AddComment
cmt.text text:=""
End If
End Sub
Sub ChangeCommentName()
'replaces old names in Excel comments
'deletes and reinserts Excel comments
' so new name appears in status bar
'www.contextures.com\xlcomments03.html
Dim ws As Worksheet
Dim cmt As Comment
Dim strOld As String
Dim strNew As String
Dim strComment As String
strNew = "New Name "
strOld = "Old Name "
Application.UserName = strNew
For Each ws In ActiveWorkbook.Worksheets
For Each cmt In ws.Comments
strComment = Replace(cmt .text, strOld,
strNew)
cmt.Delete
cmt.Parent.AddComment text :=strComment
Next cmt
Next ws
End Sub
Sub CommentAddOrEditTNR ()
'adds TimesNewRoman comment or positions
'cursor at end of existing comment text
'www.contextures.com\xlcomments03.html
Dim cmt As Comment
Set cmt = ActiveCell.Comment
If cmt Is Nothing Then
ActiveCell.AddComment text :=""
Set cmt = ActiveCell.Comment
With cmt.Shape.TextFrame.Characters.Font
.Name = "Times New Roman"
.Size = 11
.Bold = False
.ColorIndex = 0
End With
End If
SendKeys "%ie~"
End Sub
Ads by
Excel VBA Exercises Excel Programming Excel Macro Training Excel 2007
Google
Sub CommentTextFormatColour()
'adds comment then formats font colour and
adds bold
'www.contextures.com\xlcomments03.html
Dim cmt As Comment
Dim str 1 As String
Dim str 2 As String
Dim lBreak As Long
Dim lNum 1 As Long
Dim lNum 2 As Long
Dim lNumLen As Long
Dim strFind As String
On Error Resume Next
With cmt.Shape.TextFrame
.Characters(1, lBreak).Font.ColorIndex
= 3
.Characters(lBreak + 1, Len(cmt .text ))
.Font.ColorIndex = 5
End With
SendKeys "%ie~"
End Sub
Sub CommentDateTimeAdd()
'adds Excel comments with date and time ,
' positions cursor at end of comment text
'www.contextures.com\xlcomments03.html
With cmt.Shape.TextFrame
.Characters.Font .Bold = False
End With
SendKeys "%ie~"
End Sub
Sub ResetComments()
Dim cmt As Comment
For Each cmt In ActiveSheet.Comments
cmt.Shape.Top = cmt.Parent.Top + 5
cmt.Shape.Left = _
cmt.Parent.Offset(0, 1).Left + 5
Next
End Sub
Sub Comments_AutoSize()
'posted by Dana DeLouis 2000 -09-16
Sub ResizeCommentsInSelection()
'Posted by Dave Peterson 2002 -02-25
Dim mycell As Range
Dim myRng As Range
Dim lArea As Long
Ads by
Excel Download Excel Excel MS Excel Sheet Excel Experts
Google
Sub FormatAllComments()
'www.contextures.com\xlcomments03.html
Dim ws As Worksheet
Dim cmt As Comment
For Each ws In ActiveWorkbook .Worksheets
Sub ShowSheetComments()
'www.contextures.com\xlcomments03.html
'shows all comments on the active sheet
Dim c As Comment
End Sub
Application.DisplayCommentIndicator _
= xlCommentIndicatorOnly
End Sub
Application.DisplayCommentIndicator _
= xlCommentIndicatorOnly
End Sub
Sub ShowCommentsNextCell()
'based on code posted by Dave Peterson 2003-05-16
Application.ScreenUpdating = False
Application.ScreenUpdating = True
End Sub
Sub showcomments()
'posted by Dave Peterson 2003 -05-16
Application.ScreenUpdating = False
newwks.Range("A1:D1").Value = _
Array("Address", "Name", "Value", "Comment")
i = 1
For Each mycell In commrange
With newwks
i = i + 1
On Error Resume Next
.Cells(i, 1).Value = mycell.Address
.Cells(i, 2).Value = mycell.Name.Name
.Cells(i, 3).Value = mycell.Value
.Cells(i, 4).Value = mycell.Comment.Text
End With
Next mycell
Application.ScreenUpdating = True
End Sub
Sub ShowCommentsAllSheets()
'modified from code
'posted by Dave Peterson 2003 -05-16
Application.ScreenUpdating = False
Dim ws As Worksheet
Dim newwks As Worksheet
Dim i As Long
newwks.Range("A1:E1").Value = _
Array("Sheet", "Address", "Name", "Value", "Comment")
Application.ScreenUpdating = True
End Sub
Sub CopyCommentsToWord()
'www.contextures.com\xlcomments03.html
With WdApp
.Visible = True
.Documents .Add DocumentType:=0
End Sub
The following code will draw a triangular AutoShape over each comment
indicator on the active sheet:
Sub CoverCommentIndicator()
'www.contextures.com\xlcomments03.html
Dim ws As Worksheet
Dim cmt As Comment
Dim rngCmt As Range
Dim shpCmt As Shape
Dim shpW As Double 'shape width
Dim shpH As Double 'shape height
Set ws = ActiveSheet
shpW = 6
shpH = 4
End Sub
The following code will remove the triangular AutoShape over each
comment indicator on the active sheet:
Sub RemoveIndicatorShapes()
'www.contextures.com\xlcomments03.html
Dim ws As Worksheet
Dim shp As Shape
Set ws = ActiveSheet
If shp .AutoShapeType = _
msoShapeRightTriangle Then
shp.Delete
End If
End If
Next shp
End Sub
NOTE : Code is slightly different for Excel 2007 . Please use this file :
CommentNumbersPrint2007.zip
Sub CoverCommentIndicator()
'www.contextures.com\xlcomments03.html
Dim ws As Worksheet
Dim cmt As Comment
Dim lCmt As Long
Dim rngCmt As Range
Dim shpCmt As Shape
Dim shpW As Double 'shape width
Dim shpH As Double 'shape height
Set ws = ActiveSheet
shpW = 8
shpH = 6
lCmt = 1
End With
lCmt = lCmt + 1
Next cmt
End Sub
The following code will remove the rectangular AutoShape over each
comment indicator on the active sheet:
Sub RemoveIndicatorShapes()
'www.contextures.com\xlcomments03.html
Dim ws As Worksheet
Dim shp As Shape
Set ws = ActiveSheet
End Sub
Sub showcomments()
'posted by Dave Peterson 2003 -05-16
Application.ScreenUpdating = False
newwks.Range("A1:E1").Value = _
Array("Number", "Name ", "Value",
"Address", "Comment")
i = 1
For Each cmt In curwks.Comments
With newwks
i = i + 1
On Error Resume Next
.Cells(i, 1).Value = i - 1
.Cells(i, 2).Value = cmt .Parent.Name .Name
.Cells(i, 3).Value = cmt .Parent.Value
.Cells(i, 4).Value = cmt .Parent.Address
.Cells(i, 5).Value = Replace(cmt.Text ,
Chr (10), " ")
End With
Next cmt
newwks.Cells.WrapText = False
newwks.Columns.AutoFit
Application.ScreenUpdating = True
End Sub
Sub InsertComment()
'www.contextures.com\xlcomments03.html
Dim rngList As Range
Dim c As Range
Dim cmt As Comment
Dim strPic As String
Sub PictureIntoComment()
'www.contextures.com\xlcomments03.html
Dim ch As ChartObject
Dim dWidth As Double
Dim dHeight As Double
Dim ws As Worksheet
Dim sName As String
Dim cmt As Comment
Dim sPath As String
Dim sFile As String
Dim rng As Range
Set ws = ActiveSheet
Set rng = ActiveCell
sPath = ThisWorkbook.Path & "\"
sName = InputBox("Name for picture file
(no extension )", "File Name")
dWidth = Selection.Width
dHeight = Selection .Height
Selection .Cut
Set ch = ws.ChartObjects.Add
(Left:=rng.Left , Top :=rng.Top, _
Width:=dWidth, Height:=dHeight)
ch.Chart.Paste
rng.Activate
ch.Chart.Export sFile
ch.Delete
Set cmt = rng.AddComment
cmt.Text Text:=""
With cmt.Shape
.Fill.UserPicture sFile
.Width = dWidth
.Height = dHeight
End With
End Sub
Home Excel Tips Excel Files The Excel Store Blog Contact
Debra Dalgleish