Insert Comment and Shift+F2 in macro

DPARDY

New Member
Joined
Dec 3, 2009
Messages
41
Office Version
  1. 365
Platform
  1. Windows
Seems easy, but...I need a macro that will check any cell selected for a comment and then go into edit mode. If no comment, insert and go into edit mode. Thanks as always.
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
VBA Code:
Sub Commentator()
    If ActiveCell.Comment Is Nothing Then ActiveCell.AddComment
    SendKeys "+{F2}", True
End Sub
 
Upvote 0
VBA Code:
Sub Commentator()
    If ActiveCell.Comment Is Nothing Then ActiveCell.AddComment
    SendKeys "+{F2}", True
End Sub
AlphaFrog, that worked, thank you for that. How do I format the comment at the same time?
 
Upvote 0
You're welcome.
No need to quote the code back unless you are referring to specific part of it.

VBA Code:
Sub Commentator()
    If ActiveCell.Comment Is Nothing Then ActiveCell.AddComment
    With ActiveCell.Comment.Shape
        .AutoShapeType = msoShapeRoundedRectangle
        .TextFrame.Characters.Font.Name = "Tahoma"
        .TextFrame.Characters.Font.Size = 8
        .TextFrame.Characters.Font.ColorIndex = 2
        .Line.ForeColor.RGB = RGB(0, 0, 0)
        .Line.BackColor.RGB = RGB(255, 255, 255)
        .Fill.Visible = msoTrue
        .Fill.ForeColor.RGB = RGB(58, 82, 184)
        .Fill.OneColorGradient msoGradientDiagonalUp, 1, 0.23
    End With
    SendKeys "+{F2}", True
End Sub
 
Upvote 0
You're welcome.
No need to quote the code back unless you are referring to specific part of it.

VBA Code:
Sub Commentator()
    If ActiveCell.Comment Is Nothing Then ActiveCell.AddComment
    With ActiveCell.Comment.Shape
        .AutoShapeType = msoShapeRoundedRectangle
        .TextFrame.Characters.Font.Name = "Tahoma"
        .TextFrame.Characters.Font.Size = 8
        .TextFrame.Characters.Font.ColorIndex = 2
        .Line.ForeColor.RGB = RGB(0, 0, 0)
        .Line.BackColor.RGB = RGB(255, 255, 255)
        .Fill.Visible = msoTrue
        .Fill.ForeColor.RGB = RGB(58, 82, 184)
        .Fill.OneColorGradient msoGradientDiagonalUp, 1, 0.23
    End With
    SendKeys "+{F2}", True
End Sub
AlphaFrog, once again it worked perfect. Not sure the people I am presenting this to will think the format might be a little over the top. Would do I need to change for white background and a black 2pt line around??? Thanks again.
 
Upvote 0
AlphaFrog, once again it worked perfect. Not sure the people I am presenting this to will think the format might be a little over the top. Would do I need to change for white background and a black 2pt line around??? Thanks again.
 
Upvote 0
You can easily record a macro and make the formatting changes to one comment box. Then copy the relevant code from your recorded macro to the macro I provided.
 
Upvote 0
I tried that a few times, but with no luck. I am new to this but am tring...


Sub COMMENT_ALL()
If ActiveCell.Comment Is Nothing Then ActiveCell.AddComment

With ActiveCell.Comment.Font

With Selection.Font
.Name = "Arial"
.FontStyle = "Regular"
.Size = 10
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.ColorIndex = xlAutomatic
.TintAndShade = 0
.ThemeFont = xlThemeFontNone
End With
With Selection
.HorizontalAlignment = xlLeft
.VerticalAlignment = xlCenter
.ReadingOrder = xlContext
.Orientation = xlHorizontal
.AutoSize = False
End With

SendKeys "+{F2}", True

End Sub
 
Upvote 0
VBA Code:
Sub COMMENT_ALL()
   
    If ActiveCell.Comment Is Nothing Then ActiveCell.AddComment
   
    With ActiveCell.Comment.Shape
        .AutoShapeType = msoShapeRectangle  'Shape Type
        With .TextFrame
            .HorizontalAlignment = xlLeft
            .VerticalAlignment = xlCenter
            .ReadingOrder = xlContext
            .Orientation = msoTextOrientationHorizontal
            .AutoSize = False
       
            With .Characters.Font
                .Name = "Tahoma"                'Font name
                .Size = 10                      'Font size
                .ColorIndex = xlAutomatic       'Font color
            End With
        End With
       
        With .Line
            .ForeColor.RGB = RGB(0, 0, 0)
            .BackColor.RGB = RGB(255, 255, 255)
        End With
       
        With .Fill
            .Visible = msoTrue
            .ForeColor.RGB = vbWhite              'Background color
            '.OneColorGradient msoGradientDiagonalUp, 1, 0.23  'Background gradient
        End With
    End With
   
    'Comment Edit mode
    SendKeys "+{F2}", True
   
End Sub
 
Upvote 0
VBA Code:
Sub COMMENT_ALL()
  
    If ActiveCell.Comment Is Nothing Then ActiveCell.AddComment
  
    With ActiveCell.Comment.Shape
        .AutoShapeType = msoShapeRectangle  'Shape Type
        With .TextFrame
            .HorizontalAlignment = xlLeft
            .VerticalAlignment = xlCenter
            .ReadingOrder = xlContext
            .Orientation = msoTextOrientationHorizontal
            .AutoSize = False
      
            With .Characters.Font
                .Name = "Tahoma"                'Font name
                .Size = 10                      'Font size
                .ColorIndex = xlAutomatic       'Font color
            End With
        End With
      
        With .Line
            .ForeColor.RGB = RGB(0, 0, 0)
            .BackColor.RGB = RGB(255, 255, 255)
        End With
      
        With .Fill
            .Visible = msoTrue
            .ForeColor.RGB = vbWhite              'Background color
            '.OneColorGradient msoGradientDiagonalUp, 1, 0.23  'Background gradient
        End With
    End With
  
    'Comment Edit mode
    SendKeys "+{F2}", True
  
End Sub
Perfect, thanks AlphaFrog.
 
Upvote 0

Forum statistics

Threads
1,214,864
Messages
6,121,986
Members
449,060
Latest member
mtsheetz

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