Excel,自动查找插入形状的区域

Excel,自动查找插入形状的区域

当我在 excel 中插入正方形时,如何自动获取面积?
使用以下代码,我可以获取高度和宽度的消息,但我无法找到面积并在消息中显示。
此外,代码如何链接到我插入的形状?

Dim cell As Range
    Dim Width As Long
    Dim Height As Long

  For Each cell In Selection.Cells.Columns(1)
    Height = Height + cell.Height
  Next cell

  For Each cell In Selection.Cells.Rows(1)
    Width = Width + cell.Width
  Next cell

  MsgBox "Height:  " & Height & "px" & vbCr & "Width:   " _
   & Width & "px", , "Dimensions"

答案1

Sub AreaPixels()  
Dim cell As Range  
Dim Width As Long  
Dim Height As Long  

For Each cell In Selection.Cells
    Height = cell.Height
    Width = cell.Width
    cell.Value = Height * Width
    Next cell

End Sub

相关内容