Share via

Cannot set FontName and/or FontSize in an Excel Comment with Visual Basic for Applications

John Wismeijer 30 Reputation points
2026-05-22T15:52:17.31+00:00

Dear Team,

I have Microsoft 365 Personal License

I am using macOS Tahoe 26.5, Microsoft® Excel for Mac, Version 16.109.1 (26051717)

In a Visual Basic for Applications I am trying to put the font name and text size in a comment block. Translating the code gives no error, but executing the code results in Run-time error ‘1004’ Method ‘TextFrame’ of object ‘Shape’ failed. How can we solve this error. I am using the following code in a Module.

Option Explicit

Public Sub SetCommentFontSize()

  With Application

    On Error Resume Next

    .Range("C4").ClearComments

    On Error GoTo 0

    .Range("C4").AddComment

    With .Range("C4").Comment

      .Visible = False

      .Text "This is a Comment"

      With .Shape

        .Height = 30

        .Width = 200        

        With .TextFrame.Characters.Font

'          .Name = "Tahoma"

          .FontStyle = "Tahoma"

          .Size = 10

        End With

      End With

    End With

  End With

End Sub

Developer technologies | Visual Basic for Applications
0 comments No comments

Answer accepted by question author

Jack Dang (WICLOUD CORPORATION) 18,970 Reputation points Microsoft External Staff Moderator
2026-05-25T06:06:58.8766667+00:00

Hi @John Wismeijer ,

Thanks for reaching out.

The code samples below are provided as references to show the supported approach and a suitable workaround, so they may need to be adjusted to fit your workbook structure and the rest of your VBA project.

This behavior is caused by a limitation in Excel for Mac rather than by the comment text itself. On Mac, VBA can create the comment and set its text and size, but accessing .TextFrame.Characters.Font for a comment can raise run-time error 1004, so that font formatting path is not reliably supported there.

One small correction in the code is that FontStyle does not set the font family. If you want to set the font name, the correct property is .Name, for example:

With Range("C4").Comment.Shape.TextFrame.Characters.Font
  .Name = "Tahoma"
  .Size = 10
End With

Even with that correction, Excel for Mac may still fail at .TextFrame, so it does not fully resolve the issue on Mac.

If your goal is to keep using a standard Excel comment, the safest approach on Mac is to create the comment, set the text, and resize the box only, for example:

Option Explicit

Public Sub SetCommentFontSize()
  With ActiveSheet.Range("C4")
    On Error Resume Next
    .ClearComments
    On Error GoTo 0

    .AddComment
    With .Comment
      .Visible = False
      .Text "This is a Comment"
      .Shape.Height = 30
      .Shape.Width = 200
    End With
  End With
End Sub

If you need full control over font name and size from VBA on Mac, the more reliable workaround is to use a text box shape instead of a comment, because text boxes support font formatting more consistently:

Option Explicit

Public Sub AddTextboxInsteadOfComment()
  Dim ws As Worksheet
  Dim c As Range
  Dim shp As Shape

  Set ws = ActiveSheet
  Set c = ws.Range("C4")

  Set shp = ws.Shapes.AddTextbox( _
    Orientation:=msoTextOrientationHorizontal, _
    Left:=c.Left, _
    Top:=c.Top + c.Height, _
    Width:=200, _
    Height:=30)

  With shp.TextFrame2.TextRange
    .Text = "This is a Comment"
    .Font.Name = "Tahoma"
    .Font.Size = 10
  End With
End Sub

For reference, Microsoft’s VBA documentation confirms the object model and the correct properties involved here:

These pages support the object path and confirm that .Name and .Size are the proper font properties. I do not see a Microsoft VBA reference page that explicitly documents this as a Mac-specific limitation for comment formatting, so that part is based on the run-time behavior in Excel for Mac rather than on a separate platform-specific VBA article.

Hope this helps! If my explanation and the information I provided were helpful, I would greatly appreciate it if you could follow the instructions here so others with the same problem can benefit as well.

Was this answer helpful?

1 person found this answer helpful.

1 additional answer

Sort by: Most helpful
  1. AI answer

    2026-05-22T15:52:30.3633333+00:00

    On Excel for Mac, the classic comment object model is limited compared to Windows, and not all Shape.TextFrame font operations are supported. The run-time error 1004 occurs when trying to access members that are not implemented for comment shapes in this environment.

    For comments, the supported path is:

    Range("C4").AddComment
    Range("C4").Comment.Text "This is a Comment"
    

    The Range.Comment property returns a Comment object, and Comment.Shape returns the associated Shape object. However, on Mac the Shape.TextFrame.Characters.Font pipeline used to set .Name, .FontStyle, or .Size is not fully supported for comment shapes, which is why the call fails at run time even though it compiles.

    There is no supported VBA workaround in the provided object model to set Font.Name or Font.Size for a comment on Excel for Mac beyond what the platform itself exposes. The code can safely create, size, and set the text of the comment, but font formatting for comment text must be left to the default behavior on this platform.


    References:

    AI-generated content may be incorrect. Read our transparency notes for more information.

    Was this answer helpful?

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.