How do you update all existing Notes Previously known as comments and put something in the text field using VBA Code

iresolver

New Member
Joined
Oct 21, 2022
Messages
4
Office Version
  1. 2021
Platform
  1. Windows
I have over 50 blank Notes on a sheet in Excel I need to be able to update and add something to all of them and they are in merged cells. What is the VBA code to do this I can't figure it out?
Any help would be appreciated.
thanks, guys!

My VBA Code
VBA Code:
Sub My_FIX_Notes()

' This Macro will change all Note Comments to Transparent Blue Background  & Bold White Text
CommentCount = 0
Dim MyComments As Comment
Dim LArea As Long
Dim fixed As Boolean
fixed = False

For Each MyComments In ActiveSheet.Comments
With MyComments
' .Shape.Fill.OneColorGradient msoGradientDiagonalUp, 1, 0.23
.Shape.AutoShapeType = msoShapeRoundedRectangle
.Shape.TextFrame.Characters.Font.Name = "Arial"
.Shape.TextFrame.Characters.Font.Size = 12
.Shape.TextFrame.Characters.Font.ColorIndex = 2
.Shape.Line.ForeColor.RGB = RGB(0, 0, 0)
.Shape.Line.BackColor.RGB = RGB(255, 255, 255)
.Shape.Fill.Visible = msoTrue
.Shape.TextFrame.Characters.Font.Bold = True
.Shape.Fill.BackColor.RGB = RGB(58, 82, 184)

' This fills background color of the Note and sets the transarancey to 0.04
.Shape.Fill.ForeColor.RGB = RGB(85, 85, 110)
.Shape.Fill.Transparency = 0.04

'This Sets the With & Height of each Note Comment Hotkey
MyComments.Shape.Width = 200
MyComments.Shape.Height = 40

CommentCount = CommentCount + 1

End With
Next 'comment


If CommentCount > 0 Then
'MsgBox ("A total of " & CommentCount & " comments in worksheet '" & MySheet.Name & "' of workbook '" & MyWorkbook.Name & "'" & Chr(13) & "were repositioned and resized.")

MsgBox ("A Total Of " & CommentCount & "" & "Were change")

fixed = True
End If

'Next
' Next MyWorkbook
'thisfile.Activate


If fixed = False Then
MsgBox ("No comments were detected.")
End If

On Error GoTo 0

Exit Sub
End Sub
 

Attachments

  • Hotkey.jpg
    Hotkey.jpg
    215.2 KB · Views: 9

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
The new comments belong to on object called CommentsThreaded. These have only a limited set of properties you can modify.

In the VBA editor press F2 to get to the library. The search or scroll down to CommentThreaded and you can see the properties and methods it has.

A good way of finding out stuff is to record a macro in Excel, do waht you want to do and then look at the code that Excel produced.

So your code would be something like:
VBA Code:
Option Explicit

Sub My_FIX_Notes()

    ' This Macro will change all Note Comments to Transparent Blue Background  & Bold White Text
    Dim MyComments As CommentThreaded
    Dim LArea As Long
    Dim fixed As Boolean
    Dim CommentCount As Integer
    
    fixed = False
    CommentCount = 0
    
    For Each MyComments In ActiveSheet.CommentsThreaded
        With MyComments
            'set the text (dummy example)
            .Text Text:=.Text & " " & CommentCount
        
        '>>> You can't set colour or size properties of the threaded comments
        
''            ' .Shape.Fill.OneColorGradient msoGradientDiagonalUp, 1, 0.23
''            .Shape.AutoShapeType = msoShapeRoundedRectangle
''            .Shape.TextFrame.Characters.Font.Name = "Arial"
''            .Shape.TextFrame.Characters.Font.Size = 12
''            .Shape.TextFrame.Characters.Font.ColorIndex = 2
''            .Shape.Line.ForeColor.RGB = RGB(0, 0, 0)
''            .Shape.Line.BackColor.RGB = RGB(255, 255, 255)
''            .Shape.Fill.Visible = msoTrue
''            .Shape.TextFrame.Characters.Font.Bold = True
''            .Shape.Fill.BackColor.RGB = RGB(58, 82, 184)
''
''            ' This fills background color of the Note and sets the transarancey to 0.04
''            .Shape.Fill.ForeColor.RGB = RGB(85, 85, 110)
''            .Shape.Fill.Transparency = 0.04
''
''            'This Sets the With & Height of each Note Comment Hotkey
''            MyComments.Shape.Width = 200
''            MyComments.Shape.Height = 40
            
            CommentCount = CommentCount + 1
        
        End With
    Next 'comment
    
    
    If CommentCount > 0 Then
        'MsgBox ("A total of " & CommentCount & " comments in worksheet '" & MySheet.Name & "' of workbook '" & MyWorkbook.Name & "'" & Chr(13) & "were repositioned and resized.")
        
        MsgBox ("A Total Of " & CommentCount & "" & " comments were changed")
        
        fixed = True
    End If
    
    'Next
    ' Next MyWorkbook
    'thisfile.Activate
    
    
    If fixed = False Then
        MsgBox ("No comments were detected.")
    End If
    
    On Error GoTo 0
    
    Exit Sub
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,888
Messages
6,175,206
Members
452,618
Latest member
Tam84

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top