VBA Powerpoint修改活动表Cell Gradient

时间:2016-12-06 11:17:06

标签: vba macros powerpoint gradient powerpoint-vba

我试图在Powerpoint中创建一个可以调整渐变的宏。填充所选表格中所选单元格的设置。

我已经使用Excel轻松完成了这项工作,但我无法为Powerpoint最好地复制它,我设法做的就是调整单一填充颜色。已阅读各种网站,但尚未取得任何进展,我将不胜感激任何有关如何在下面的Excel代码中创建相同效果的建议。

*编辑:让它工作了一点但仍然不是100%满意的颜色。

Excel代码:(工作)

ActiveCell.Select
With Selection.Interior
    .Pattern = xlPatternLinearGradient
    .Gradient.Degree = 90
    .Gradient.ColorStops.Clear
End With
With Selection.Interior.Gradient.ColorStops.Add(0)
    .ThemeColor = xlThemeColorDark1
    .TintAndShade = 0
End With
With Selection.Interior.Gradient.ColorStops.Add(1)
    .Color = 39372
    .TintAndShade = 0
End With

PowerPoint代码(WIP)

Dim oSh As Shape
Dim oTbl As Table
Dim lRow As Long ' your i
Dim lCol As Long ' your j
Set oSh = ActiveWindow.Selection.ShapeRange(1)
Set oTbl = oSh.Table

With oTbl
    For lRow = 1 To .Rows.Count
        For lCol = 1 To .Columns.Count
            If .Cell(lRow, lCol).Selected Then
                With .Cell(lRow, lCol).Shape
                    .Fill.TwoColorGradient msoGradientHorizontal, 1
                .Fill.ForeColor.RGB = RGB(255, 222, 129)
                 .Fill.BackColor.RGB = RGB(208, 154, 0)

                  End With
            End If
        Next
    Next
End With

End Sub

1 个答案:

答案 0 :(得分:0)

我看到你让它运转了。如果您不喜欢您使用的RGB颜色,我首先在PowerPoint UI中设计样式,然后对您设计的内容进行编码。要拥有一个多站(超过2个)渐变,您可以像这样添加句号:

Sub TableCellGradient()
  Dim oSh As Shape
  Dim oTbl As Table
  Dim lRow As Long ' your i
  Dim lCol As Long ' your j
  Set oSh = ActiveWindow.Selection.ShapeRange(1)
  Set oTbl = oSh.Table

  With oTbl
    For lRow = 1 To .Rows.Count
      For lCol = 1 To .Columns.Count
        If .Cell(lRow, lCol).Selected Then
          With .Cell(lRow, lCol).Shape.Fill
            .TwoColorGradient msoGradientHorizontal, 1
            .ForeColor.RGB = RGB(255, 222, 129)
            .BackColor.RGB = RGB(208, 154, 0)
            .GradientStops.Insert RGB(255, 255, 255), 0.5, 1
          End With
        End If
      Next
    Next
  End With
End Sub