首页 > 解决方案 > 如何使用 SendKeys 插入注释?

问题描述

我有 Microsoft Office 365 2019。

我问了一个关于“插入注释”的问题.Fill.UserPicture

我仍然有一些错误。

请参阅截屏视频

我发现了问题,它是SendKeys "+{F2}"(插入注释后它是打开的注释)。

Sub Special_Note2_FillPicture(control As IRibbonControl)

    Dim img As FileDialog
    Dim i_add As String

    Set img = Application.FileDialog(msoFileDialogFilePicker)
        img.AllowMultiSelect = False
        img.Title = "Select the Image!"
        img.Show

    If img.SelectedItems.Count < 1 Then        
        MsgBox "No Image Selected"        
    Exit Sub

    Else            
        i_add = img.SelectedItems(1)
    End If


    Dim myComm As Comment
      If Not ActiveCell.Comment Is Nothing Then
        If MsgBox("The cell already contains a note, delete?", 4) - 7 Then
          ActiveCell.Comment.Delete
        Else: Exit Sub
        End If
      End If

    Set myComm = ActiveCell.AddComment
        With myComm.Shape
          .Height = 110
          .Width = 200
          .AutoShapeType = 1             'form
'          .Fill.UserTextured
          .Fill.UserPicture i_add
          .Line.ForeColor.RGB = RGB(255, 0, 0)
          .DrawingObject.Font.Name = "Consolas"
          .DrawingObject.Font.FontStyle = "normal"
          .DrawingObject.Font.Size = 8
        End With
          'emulate the choice of "Change note"
           SendKeys "+{F2}"
End Sub

标签: excelvba

解决方案


0Key 我找到了解决方案。我稍微重写了代码:

Sub Note_FiilPictureDialog(control As IRibbonControl)
    Dim img As FileDialog
    Dim i_add As String
    Dim myComm As Comment

    Set img = Application.FileDialog(msoFileDialogFilePicker)
        img.AllowMultiSelect = False
        img.Title = "Select the Image!"
        img.Show

    If img.SelectedItems.Count < 1 Then
    Exit Sub

    Else
        i_add = img.SelectedItems(1)
    End If

'If the cell contains a `Note` delete!
    If Not ActiveCell.Comment Is Nothing Then
        ActiveCell.Comment.Delete
    End If

    On Error GoTo nexterr
    ActiveCell.ClearComments

    Set myComm = ActiveCell.AddComment
        With myComm.Shape
          .Height = 110
          .Width = 200
          .AutoShapeType = 1             'form
'          .Fill.UserTextured
          .Fill.UserPicture i_add
          .Line.ForeColor.RGB = RGB(255, 0, 0)
          .DrawingObject.Font.Name = "Consolas"
          .DrawingObject.Font.FontStyle = "normal"
          .DrawingObject.Font.Size = 8
          'emulate the choice of "Change note".
           SendKeys "+{F2}"
          Exit Sub

nexterr:
        MsgBox "You can only select images!", vbCritical, "Error"
        ActiveCell.ClearComments
        End With
End Sub

推荐阅读