我需要根据excel值更改ppt文件中的形状颜色。我一直在尝试以下代码,但无法正常工作。逻辑是:
如果我正在分析产品A(单元),我想知道它是否有利可图(cell.offset(0,39)= 1)或否(= 0)。如果它是有利可图的,那么我需要它在PPT演示文稿中将确定的形状(对应此产品)绘制为绿色。
您能帮我吗?
Sub UpdateShapes ()
'Setting ranges and variables
Dim cell, RangeID As Range
Set RangeID = Sheets("Teste").Range("d1:d20")
' Get a PowerPoint instance.
Dim ppapp As Object
Set ppapp = New PowerPoint.Application
' PowerPoint window visible
Dim pres As PowerPoint.Presentation
strPpPath = ThisWorkbook.Path
strPpName = strPpPath & "\" & "Trial01_Rob.pptx" 'Subtituir pelo nome do seu ppt
Set pres = ppapp.Presentations.Open( _
Filename:=strPpName, Untitled:=msoFalse)
For Each cell In RangeID
If cell.Offset(0, 39).Value = 1 Then
pres.slides(1).Shapes(cell).Fill.ForeColor.RGB = RGB(231, 28, 87)
Else
pres.slides(1).Shapes(cell).Fill.ForeColor.RGB = RGB(0, 28, 87)
End If
Next
End Sub