vbscript “扫描”PowerPoint中表格中所有单元格的颜色代码,然后在同一维度的另一个表格上“打印”相同的颜色。

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了vbscript “扫描”PowerPoint中表格中所有单元格的颜色代码,然后在同一维度的另一个表格上“打印”相同的颜色。相关的知识,希望对你有一定的参考价值。

Sub TableColourCopier()

If MsgBox("Make sure that you have selected two tables. The first table you select is a DONOR TABLE. The second table receives the colour formatting of the first one. Continue?", vbYesNo) _
= vbNo Then Exit Sub

Dim ncol, nrow, ncells As Long

ncol = ActiveWindow.Selection.ShapeRange(1).Table.Columns.Count
nrow = ActiveWindow.Selection.ShapeRange(1).Table.Rows.Count

'Get total number of cells
ncells = ncol * nrow

Dim c() As Long
'c = ActiveWindow.Selection.ShapeRange(1).Fill.ForeColor.RGB

ReDim c(1 To ncells)

Dim i, j, k As Long

j = k = 1
i = 1

'Loop through every cell in a table
For j = 1 To nrow
    For k = 1 To ncol
        'ActiveWindow.Selection.ShapeRange(1).Table.Cell(j, k).Shape.Fill.ForeColor.RGB = RGB(255, 0, 0)
        c(i) = ActiveWindow.Selection.ShapeRange(1).Table.Cell(j, k).Shape.Fill.ForeColor.RGB
        'ActiveWindow.Selection.ShapeRange(1).Table.Cell(j, k).Shape.TextFrame.TextRange.Text = i
        i = i + 1
    Next
Next

'Check that the colour has been correctly memorised
Dim colorcode As Integer
For colorcode = 1 To ncells
    Debug.Print c(colorcode)
Next

j = k = 1 'reset values to 1
i = 1

Debug.Print i

'Loop through every cell in table 2
For j = 1 To nrow
    For k = 1 To ncol
        'ActiveWindow.Selection.ShapeRange(1).Table.Cell(j, k).Shape.Fill.ForeColor.RGB = RGB(255, 0, 0)
        ActiveWindow.Selection.ShapeRange(2).Table.Cell(j, k).Shape.Fill.ForeColor.RGB = c(i)
        'ActiveWindow.Selection.ShapeRange(2).Table.Cell(j, k).Shape.TextFrame.TextRange.Text = i
        i = i + 1
    Next
Next

End Sub


以上是关于vbscript “扫描”PowerPoint中表格中所有单元格的颜色代码,然后在同一维度的另一个表格上“打印”相同的颜色。的主要内容,如果未能解决你的问题,请参考以下文章

vbscript [创建表格图例]在PowerPoint #PowerPoint中创建一行迷你表格图例

vbscript 调整PowerPoint图表的数据标签

vbscript 在PowerPoint中调整散点图的标签

vbscript 在PowerPoint中调整散点图的标签

vbscript 更改PowerPoint图表中散点图上所有点的颜色

vbscript 调整演示文稿[PowerPoint VBA]中的所有图表的大小和重新定位