Excel VBA to change Comments font on key in

KSKWin

New Member
Joined
May 7, 2023
Messages
10
Office Version
  1. 2019
Platform
  1. Windows
How to get the Excel comment's font to be changed to the desired font (caliber) while keying in the comment box by VBA macro code.

This is code currently using, but every time i need to play.

Sub FixComments()
Dim cmt As Comment
For Each cmt In ActiveSheet.Comments
With cmt.Shape.TextFrame.Characters.Font
.Name = "Calibri"
.Size = 8
End With
Next cmt
End Sub
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
Welcome to the MrExcel Message Board!

Cross-posting (posting the same question in more than one forum) is not against our rules, but the method of doing so is covered by #13 of the Forum Rules.

Be sure to follow & read the link at the end of the rule too!

Cross posted at:

There is no need to repeat the link(s) provided above but if you have posted the question at other places, please provide links to those as well.

If you do cross-post in the future and also provide links, then there shouldn’t be a problem.
 
Upvote 0
while keying in the comment box
I don't think that can be done. The best you might be able to do is to incorporate some event code.

VBA Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    Call FixComments
End Sub

Sub FixComments()
    Dim cmt As Comment
    For Each cmt In ActiveSheet.Comments
        With cmt.Shape.TextFrame.Characters.Font
            If Not (.Name = "Calibri" And .Size = 8) Then
                .Name = "Calibri"
                .Size = 8
            End If
        End With
    Next cmt
End Sub
 
Upvote 1
Solution
HI,

Pl. help in avoiding infinite looping by implementing [B]Application.EnableEvents = False[/B], Since it hangs.

Pl share the updated code.

Thanks
KSK
 
Upvote 0
I don't think that can be done. The best you might be able to do is to incorporate some event code.

VBA Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    Call FixComments
End Sub

Sub FixComments()
    Dim cmt As Comment
    For Each cmt In ActiveSheet.Comments
        With cmt.Shape.TextFrame.Characters.Font
            If Not (.Name = "Calibri" And .Size = 8) Then
                .Name = "Calibri"
                .Size = 8
            End If
        End With
    Next cmt
End Sub
HI,

Pl. help in avoiding infinite looping by implementing [B]Application.EnableEvents = False[/B], Since it hangs.

Pl share the updated code.

Thanks
KSK
 
Upvote 0
HI,

Pl. help in avoiding infinite looping by implementing [B]Application.EnableEvents = False[/B], Since it hangs.

Pl share the updated code.

Thanks
KSK

There is nothing in the example code I posted that would cause infinite looping. It is an explicitly finite loop. I have no updated code to share.
 
Upvote 0
There is nothing in the example code I posted that would cause infinite looping. It is an explicitly finite loop. I have no updated code to share.
I don't see how it would create an infinite loop either, though every time a cell is selected on the sheet it will cycle through every comment on the page.
If they don't want that to happen every time, maybe they can move it to a different event, like Workbook_Open or Workbook_Close.
Then the updates might not be immediate, but would be updated whenever the workbook is opened or closed.
 
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,249
Members
452,623
Latest member
Techenthusiast

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