vba - 需要 VBA 代码将形状(例如:向下箭头/向上箭头)放置在 power point 幻灯片中表格的特定单元格(基于单元格值)的顶部
问题描述
根据 Power Point 表中单元格的值,我需要帮助编写用于在单元格上放置形状的 VBA 代码。假设如果我有一张幻灯片中有 3 行 3 列的表格,并且我的表格在每个单元格中都包含一些随机数。如果单元格值小于 5,那么我想使用 VBA 代码在单元格顶部添加或放置一个向下箭头形状 (↓)。
Sub SetTableFont1()
Dim oShp As Shape
Dim oTbl As Table
Dim oSld As Slide
Dim I As Long
Dim J As Long
For Each oSld In ActivePresentation.Slides
For Each oShp In oSld.Shapes
If oShp.HasTable Then
Set oTbl = oShp.Table
For I = 1 To oTbl.Columns.Count
For J = 1 To oTbl.Rows.Count
ActivePresentation.Slides(1).Shapes("Down").Copy
' I have copied a down arrow shape which is manually added in the slide
and i named it as "Down"
'Now I am going to select the cells of the table and i want to paste that
copied down arrow shape on top of the selected cell.
oTbl.Cell(J, I).Select
If oTbl.Cell(J, I).Value <= 5 Then
oTbl.Cell(J, I).Paste
End If
Next J
Next I
End If
Next oShp
Next oSld
End Sub
Please help me on above code.
Below is screenshot for Reference
解决方案
粘贴到单元格中是行不通的。理论上,您可以获取表格的位置和尺寸,然后创建一个包含行宽和列高的二维数组。然后在找到目标单元格后,计算其位置并将箭头设置为这些坐标。但是,如果任何单元格被合并或细分,您将得到不正确的结果,因为在 VBA 中没有任何简单的方法可以识别这些单元格。
推荐阅读
- java - BST 中的水平遍历。队列不合作
- php - 快速PHP分页不起作用
- javascript - 在对话框中单击按钮时将今天的日期传递给 EditText 变量
- angular - 手动销毁组件
- java-9 - Java 9 - 列表类:of() 带有可变参数的重载方法
- google-cloud-platform - 谷歌云平台无权SSH下载
- java - Java中的三元组是什么?
- tfs - TFS 服务器丢失,而后端 SQL Server 完好无损。如何将源代码迁移到 VSTS?
- linux - 在所有 bash 命令后自动运行命令?
- idris - 如何在 Idris 中编写一个简单的基于列表的快速排序?