有没有办法在 PowerPoint VBA 中使用形状的 ID 来确定它的颜色?
Is there a way to use a Shape's ID in PowerPoint VBA to then determine it's color?
我有一个宏可以从大约 25 张单独的幻灯片构建一个合并的 PowerPoint 演示文稿。幻灯片有一个状态圈,可以是红色、黄色或绿色,以显示当前状态。我想提取这些形状的颜色并放入 excel 文件中。我曾尝试使用形状索引号来引用代码中的形状,但特定形状的索引在每张幻灯片上都会发生变化;它不一致。 Shape ID 好像是一致的,但是我想不通VBA中的Shape ID 怎么用。这是我目前正在使用的:
With ActivePresentation.Slides(IForLoop).Shapes(8).Fill.ForeColor
data = ActivePresentation.Slides(IForLoop).Shapes(8).Fill.Forecolor
If Instr(1 , data, "255"), Then
LArray (I, sStatus) = "Red"
ElseIf InStr(1, data, "65535") Then
LArray (I, sStatus) = "Yellow"
ElseIf InStr(1, data, "5287936") Then
LArray (I, sStatus) = "Green"
End If
问题是每张幻灯片的 Shape 参考 Shape(8) 都不一致,所以我没有得到正确的颜色名称来填充我的 Excel 文件。
谢谢。
未测试:
'...
Dim shp As Shape
Set shp = getShapeByID(yourIdHere, ActivePresentation.Slides(IForLoop))
If Not shp Is Nothing then
Select Case shp.Fill.ForeColor
Case 255: LArray (I, sStatus) = "Red"
Case 65535: LArray (I, sStatus) = "Yellow"
Case 5287936: LArray (I, sStatus) = "Green"
End Select
End If
'...
'Get a shape from its Id
Function getShapeByID(shapeID As Long, sl As Slide) As Shape
Dim s As Shape
For Each s In sl.Shapes
If s.id = shapeID Then
Set getShapeByID = s
Exit Function
End If
Next
End Function
我有一个宏可以从大约 25 张单独的幻灯片构建一个合并的 PowerPoint 演示文稿。幻灯片有一个状态圈,可以是红色、黄色或绿色,以显示当前状态。我想提取这些形状的颜色并放入 excel 文件中。我曾尝试使用形状索引号来引用代码中的形状,但特定形状的索引在每张幻灯片上都会发生变化;它不一致。 Shape ID 好像是一致的,但是我想不通VBA中的Shape ID 怎么用。这是我目前正在使用的:
With ActivePresentation.Slides(IForLoop).Shapes(8).Fill.ForeColor
data = ActivePresentation.Slides(IForLoop).Shapes(8).Fill.Forecolor
If Instr(1 , data, "255"), Then
LArray (I, sStatus) = "Red"
ElseIf InStr(1, data, "65535") Then
LArray (I, sStatus) = "Yellow"
ElseIf InStr(1, data, "5287936") Then
LArray (I, sStatus) = "Green"
End If
问题是每张幻灯片的 Shape 参考 Shape(8) 都不一致,所以我没有得到正确的颜色名称来填充我的 Excel 文件。
谢谢。
未测试:
'...
Dim shp As Shape
Set shp = getShapeByID(yourIdHere, ActivePresentation.Slides(IForLoop))
If Not shp Is Nothing then
Select Case shp.Fill.ForeColor
Case 255: LArray (I, sStatus) = "Red"
Case 65535: LArray (I, sStatus) = "Yellow"
Case 5287936: LArray (I, sStatus) = "Green"
End Select
End If
'...
'Get a shape from its Id
Function getShapeByID(shapeID As Long, sl As Slide) As Shape
Dim s As Shape
For Each s In sl.Shapes
If s.id = shapeID Then
Set getShapeByID = s
Exit Function
End If
Next
End Function