VBA excel 获取图片的位置坐标
时间: 2023-07-27 22:14:28 浏览: 62
要获取 Excel 中图像的位置坐标,你可以使用 `Shape` 对象。以下代码将获取名为 `Picture 1` 的图像的位置坐标并将其打印出来:
```
Sub GetPicturePosition()
Dim shp As Shape
Set shp = ActiveSheet.Shapes("Picture 1")
Debug.Print "Left: " & shp.Left
Debug.Print "Top: " & shp.Top
End Sub
```
这将在 VBA 的调试窗口中显示图像的左侧和顶部位置坐标。你也可以使用 `Width` 和 `Height` 属性来获取图像的宽度和高度,例如:
```
Sub GetPictureSize()
Dim shp As Shape
Set shp = ActiveSheet.Shapes("Picture 1")
Debug.Print "Width: " & shp.Width
Debug.Print "Height: " & shp.Height
End Sub
```
这将在 VBA 的调试窗口中分别显示图像的宽度和高度。
相关问题
vba excel 获取图片的位置坐标
要获取 Excel 中图像的位置坐标,你可以使用 `Shape` 对象。以下代码将获取名为 `Picture 1` 的图像的位置坐标并将其打印出来:
```
Sub GetPicturePosition()
Dim shp As Shape
Set shp = ActiveSheet.Shapes("Picture 1")
Debug.Print "Left: " & shp.Left
Debug.Print "Top: " & shp.Top
End Sub
```
这将在 VBA 的调试窗口中显示图像的左侧和顶部位置坐标。你也可以使用 `Width` 和 `Height` 属性来获取图像的宽度和高度,例如:
```
Sub GetPictureSize()
Dim shp As Shape
Set shp = ActiveSheet.Shapes("Picture 1")
Debug.Print "Width: " & shp.Width
Debug.Print "Height: " & shp.Height
End Sub
```
这将在 VBA 的调试窗口中分别显示图像的宽度和高度。
vba excel 获取单元格的坐标
你可以使用 Range 对象的 Address 属性来获取单元格的坐标。例如,以下代码将获取 A1 单元格的坐标并将其打印出来:
```
Sub GetCellAddress()
Dim cell As Range
Set cell = Range("A1")
Debug.Print cell.Address
End Sub
```
这将在 VBA 的调试窗口中显示 `$A$1`。你也可以使用 `Row` 和 `Column` 属性来获取单元格的行号和列号,例如:
```
Sub GetCellRowAndColumn()
Dim cell As Range
Set cell = Range("A1")
Debug.Print "Row: " & cell.Row
Debug.Print "Column: " & cell.Column
End Sub
```
这将在 VBA 的调试窗口中分别显示 `Row: 1` 和 `Column: 1`。