欢迎光临散文网 会员登陆 & 注册

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

2023-08-14 22:02 作者:ch_j  | 我要投稿

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

VBA——批量设置PPT单元格数字格式的评论 (共 条)

分享到微博请遵守国家法律