excel - 我可以在 vba 中使用 shape.width 作为条件吗
问题描述
我想在 if 中使用形状的宽度作为条件。我下面的代码会自动将数字添加到单元格范围内的形状中。
Sub numShapeMasqueD()
Dim shapeTemp As Shape
Dim masqueD As Range
Dim cpt As Integer
Dim row As Long, col As Long
Set masqueD = Range("h22:r31")
cpt = 1
For row = 1 To masqueD.Rows.Count
For col = 1 To masqueD.Columns.Count
For Each shapeTemp In ActiveSheet.Shapes
If Not Intersect(masqueD.Cells(row, col), shapeTemp.TopLeftCell) Is Nothing Then
shapeTemp.TextFrame.Characters.Text = cpt
cpt = cpt + 1
End If
Next shapeTemp
Next col
Next row
End Sub
我尝试shapeTemp.width
在 If 中使用 as 条件。我想要做的是如果 shapeTemp 的宽度低于12.97016然后设置shapeTemp.TextFrame.Characters.Font = 8
。
我希望我清楚地解释了我的问题。
解决方案
反而,
为什么不创建另一个变量并将值设置为 ShapeTemp.Width 同样就像 jeeped 评论的那样,您需要实际声明 shapeTemp。
Dim shapeTemp as Shape
Dim shapeWidth as Double
shapeWidth = shapeTemp.Width
If shapeWidth = 12.907016 then
shapeTemp.TextFrame.Characters.Font = 8
End If
推荐阅读
- encryption - 如何在 Crypto JS 中为邮递员实现 AES 128
- r - 在 R 中为 Google BigQuery 使用 IN 运算符
- javascript - 获取会话 cookie(xss、payload)
- java - 如何使用 Android Studio 上的按钮在我的应用程序上显示/运行 DirectMessagesList Twitter4J 代码?
- reactjs - PDF 文件下载在使用 firebase 的 React.js webapp 中不起作用(Excel 有效)
- typescript - TypeOrm NestJs Typescript 数据类型最佳实践
- .net - 如何实现权限——使用 JWT 声明或数据库?
- php - 如何使用 php 用正确的编码重写这个 xml 文件?
- flutter - Flutter:按钮需要按两次才能按要求工作
- apache-spark - Spark 历史服务器不显示所有作业