Option Explicit
Const KShCom = "CmtSh"
Dim ShCom As Shape
Dim ShHg As Long
Private Sub CreateBigShape()
On Error Resume Next
With ShCom
.DrawingObject.Font.Name = "Verdana"
.DrawingObject.Font.Size = 13
.Name = KShCom
.Left = ActiveCell.Left - 10
.Top = ActiveCell.Top - 10
End With
End Sub
Private Sub CreateSmallShape()
On Error Resume Next
ActiveSheet.Shapes(KShCom).Delete
Set ShCom = ActiveSheet.Shapes.AddTextbox(msoTextOrientationHorizontal, 1, 1, 20, 20)
With ShCom
.Name = KShCom
.Left = ActiveCell.Left + 7
.Top = ActiveCell.Top + 7
End With
End Sub
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
On Error Resume Next
With Target
If .Count = 1 And Not Intersect(Target, [Rng]) Is Nothing Then
If ShCom Is Nothing Then
CreateSmallShape
Application.Wait (Now + TimeValue("0:00:05"))
CreateBigShape
End If
If Not ShCom.Visible Then Exit Sub
CreateSmallShape
Application.Wait (Now + TimeValue("0:00:05"))
ShCom.Left = .Left - 8
ShCom.Top = .Top - 8
ShCom.Height = .Height + 18
ShHg = .Height + 18
ShCom.Width = .Width + 18
ShCom.DrawingObject.Text = .Text
ShCom.TextFrame.AutoSize = True
ShCom.TextEffect.Alignment = msoTextEffectAlignmentStretchJustify
If ShCom.Height < ShHg Then ShCom.Height = ShHg
Else
ShCom.Visible = msoFalse
End If
End With
End Sub
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
If Target.Count <> 1 Or Intersect(Target, [Rng]) Is Nothing Then Exit Sub
If ShCom Is Nothing Then
CreateSmallShape
Application.Wait (Now + TimeValue("0:00:05"))
CreateBigShape
End If
CreateSmallShape
Application.Wait (Now + TimeValue("0:00:05"))
With ShCom
.Visible = Not .Visible
If .Visible Then
.Left = Target.Left - 8
.Top = Target.Top - 8
ShHg = Target.Height + 18
.Width = Target.Width + 18
.DrawingObject.Text = Target.Text
.TextFrame.AutoSize = True
.TextEffect.Alignment = msoTextEffectAlignmentCentered
If .Height < ShHg Then .Height = ShHg
End If
End With
Cancel = True
End Sub