VBA——批量设置PPT单元格数字格式

Rem 本视频完整代码
Sub 表格负数格式()
'注意:会设置当前演示文稿中每页幻灯片的每个表格
Dim sld As PowerPoint.Slide
Dim tb As Table
Dim sp As Shape
Dim i As Long
Dim j As Long
Dim cel As Cell
Dim s As String
For Each sld In ActivePresentation.Slides
For Each sp In sld.Shapes
If sp.HasTable Then
Set tb = sp.Table
For i = 1 To tb.Rows.Count
For j = 1 To tb.Columns.Count
Set cel = tb.Cell(i, j)
s = cel.Shape.TextFrame.TextRange.Text
'Debug.Print s
s = Trim(s)
If Right(s, 1) = "%" Then
s = Mid(s, 1, Len(s) - 1)
End If
If IsNumeric(s) Then
If Val(s) < 0 Then
cel.Shape.TextFrame.TextRange.Font.Color.RGB = RGB(255, 0, 0)
End If
End If
Next j
Next i
End If
Next sp
Next sld
Set tb = Nothing
Set cel = Nothing
End Sub