我编写了以下程序,通过单击自定义选项卡上的自定义图标运行。
程序应该:
代码如下:
Sub AdjustRowHeightToCode(control As IRibbonControl)
'Sub AdjustRowHeightToCode()
'A procedure that sets height of a merged cell in which shape is located
Dim wsh As Worksheet
Dim i As Integer
Dim col_n As Long
Dim sh As Shape
Dim sh_cell As Range
Set wsh = ThisWorkbook.Worksheets("Wyniki")
For Each sh In wsh.Shapes
Set sh_cell = sh.TopLeftCell
col_n = sh_cell.Column
If col_n >= 2 And col_n <= 5 Then
'We want to set height of cells from columns B to E
sh.Select
sh_cell.RowHeight = sh.Height + 10
End If
Next sh
End Sub
当我通过单击图标运行程序时,我得到
运行时错误“1004”: 应用程序定义或对象定义的错误
For
循环中的调试器停止并且似乎没有检测到“sh.TopLeftCell”属性,如下面的屏幕所示。
相反,它能够检测
Colum
甚至Row
属性sh_cell
。
我还是不明白为什么调试器会在此时停止? 你有什么线索吗?