excel - 如何使用 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
解决方案
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
推荐阅读
- mockito - 在 JdbcTemplate 中模拟重载方法 queryForObject
- ef-core-2.0 - Find' 的类型为 'int',与 'long' 的属性类型不匹配
- angular - 每次在 ng-template 中设置输入焦点
- javascript - 动态属性访问器
- r - 如何修复for循环,因为它只返回最后一次迭代
- delphi - TClientDataSet 对字符串字段使用过多内存
- shell - 预期条件在脚本中不起作用且没有错误
- html - 调整浏览器窗口大小时,html 页面 (body) 的宽度未扩展
- python - 查找数组中某些元素的所有组合
- sql - 如何在查询中链接两条记录