|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
PPT VBA——设置表格单元格数字格式
一、示例代码
- Sub 表格负数格式()
- 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 sp In ActivePresentation.Slides(1).Shapes
- ' i = i + 1
- ' If sp.HasTable Then
- ' MsgBox i
- ' End If
- ' Next
- Set tb = ActivePresentation.Slides(1).Shapes(6).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
-
- Set tb = Nothing
- Set cel = Nothing
- End Sub
复制代码
|
|