vba excel 还原图片原始大小
时间: 2023-07-19 07:30:11 浏览: 108
在VBA中,可以使用`Shapes`对象来处理Excel中的图片。要还原图片的原始大小,可以使用以下代码:
```vba
Sub ResetPictureSize()
Dim pic As Shape
For Each pic In ActiveSheet.Shapes
'仅处理图片类型的Shape
If pic.Type = msoPicture Then
'设置图片大小为原始大小
pic.ScaleHeight 1, msoFalse, msoScaleFromTopLeft
pic.ScaleWidth 1, msoFalse, msoScaleFromTopLeft
End If
Next
End Sub
```
这个代码会遍历当前活动工作表中的所有形状(包括图片),并将它们的大小设置为原始大小。注意,这个代码对于所有的形状都会生效,如果你只想处理图片类型的形状,可以添加一个判断语句,只处理类型为`msoPicture`的形状。
相关问题
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 获取图片的位置坐标
要获取 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 的调试窗口中分别显示图像的宽度和高度。