excel - 如何区分VBA代码excel中选择的图片?
问题描述
我是 VBA 编码的初学者。我尝试在Excel中排列3张图片如下:
使所有选定的图片大小相同。
将选择的 3 张图片彼此相距 188 点,排成 1 行。
我的问题是我不知道如何区分图片。使用我的代码,图片重叠。那是我的代码:
Sub ArrangePics()
' ArrangePics Macro
Dim objPic As Object
For Each objPic In ActiveSheet.Pictures
With objPic.ShapeRange
.LockAspectRatio = False
.Height = Application.CentimetersToPoints(4.1)
.Width = Application.CentimetersToPoints(5.1)
End With
Next
Selection.ShapeRange.Distribute msoDistributeHorizontally, msoFalse
Dim intX As Integer
intX = 1
Dim i As Long
For i = 0 To 2 Step 1
Selection.ShapeRange.Left = intX * 188
Next
' Selection.Cut
End Sub
解决方案
你可以在这之后:
Dim xPic As Long
Dim objPic As Object
For Each objPic In Selection
If TypeOf objPic Is Picture Then ' be sure to deal with pics only
With objPic.ShapeRange
.LockAspectRatio = False
.Height = Application.CentimetersToPoints(4.1)
.Width = Application.CentimetersToPoints(5.1)
.Top = 200 ' same row for all pictures
.Left = xPic
xPic = xPic + 188 ' update xPic
End With
End If
Next
推荐阅读
- c# - 如何防止“索引”在 Action 数组中更新自身
- html - 如何在 XPath/CSS 定位器中排除一个孩子
- c++ - 无法通过 QModelIndex 从 QTreeView 获取项目
- database - 如何从 Visual Studio 2017 将 localdb 发布到 Azure
- azure - Visual Studio 2019 中缺少 Application Insights
- android - React Native 中的序列动画
- c# - 如何找到浏览器当前的显示语言?
- kotlin - != null VS ?.let { } kotlin 中不可变变量的性能
- azure - 登录请求被 azure waf 阻止
- php - 自动将Gettext添加到目录中所有php文件中的所有日文文本中