|
楼主 |
发表于 2023-2-7 22:38
|
显示全部楼层
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
本帖最后由 ning84 于 2023-2-8 15:54 编辑
又做了一遍题目,有点感觉。
再次感谢lss001的帮助。
- Private Sub del()
- Dim Rng As Range
- Dim Ppt As PowerPoint.Application
- Dim Pres As Presentation
- Dim Sld As Slide
- Dim Shp 'As Shape
- Dim oTab As Table
- Dim TabRow As Integer, TabCol As Integer
- Dim oSum, oNum As Integer
- Dim FontSize
- TabRow = 27
- TabCol = 4
- ''
- Set Ppt = New PowerPoint.Application
- Ppt.Visible = msoTrue
- Set Pres = Ppt.Presentations.Add
- With Pres.PageSetup
- .SlideSize = ppSlideSizeCustom
- .SlideWidth = 720
- .SlideHeight = 425
- ''.FirstSlideNumber = 1
- .SlideOrientation = msoOrientationHorizontal
- .NotesOrientation = msoOrientationVertical
- End With
- ''
- oSum = 1
- oNum = 1
- For kk = 1 To Rng.Rows.Count
- With Pres
- Set Sld = .Slides.Add(.Slides.Count + 1, ppLayoutBlank)
- Sld.MoveTo .Slides.Count
- End With
- oSum = oSum + ii
- Set Shp = Sld.Shapes.AddTable(TabRow, TabCol, 0, 0, 100)
- With Shp
- .Left = 10
- .Top = 10
- End With
- Set oTab = Shp.Table
- With oTab
- For jj = 1 To TabCol
- .Columns.Item(jj).Width = ww
- Next jj
- .ApplyStyle Rng(kk, 1), True
- .Cell(1, 1).Merge .Cell(1, TabCol)
- .Cell(1, 1).Shape.TextFrame.TextRange.Text = Rng(1, 2)
- For ii = 2 To TabRow
- For jj = 1 To TabCol
- .Rows.Item(ii).Height = 1
- .Cell(ii, jj).Shape.TextFrame.TextRange.Text = oNum & "+" & oSum & "=" & Application.WorksheetFunction.Text(oNum + oSum, "[DBNum1]")
-
- oNum = oNum + 1
- oSum = oSum + oNum
- Next jj
- Next ii
- End With
- Next kk
- End Sub
-
复制代码 再优化一下
- ''
- Function SldNewOneTable(Pres As Presentation, DataArr, TabSty, FontSize, MergeStr, Left, Top, TabRow, TabCol, ColWidArr)
- Dim Sld As Slide
- Dim Shp
- Dim oTab As Table
- Dim Sss
- ''
- With Pres
- Set Sld = .Slides.Add(.Slides.Count + 1, ppLayoutBlank)
- Sld.MoveTo .Slides.Count
- End With
- If MergeStr = "" Then
- Set Shp = Sld.Shapes.AddTable(TabRow, TabCol, 0, 0, 100)
- Else
- Set Shp = Sld.Shapes.AddTable(TabRow + 1, TabCol, 0, 0, 100)
- End If
- With Shp
- .Left = Left
- .Top = Top
- End With
- Set oTab = Shp.Table
- With oTab
- ''
- For jj = 1 To TabCol
- .Columns.Item(jj).Width = ColWidArr(jj - 1)
- Next jj
- .ApplyStyle TabSty, True
- If MergeStr = "" Then
- Sss = 0
- Else
- Sss = 1
- .ApplyStyle MergeStr, True
- If TabCol > 1 Then
- .Cell(1, 1).Merge .Cell(1, TabCol)
- End If
- .Cell(1, 1).Shape.TextFrame.TextRange.Text = MergeStr
- End If
- For ii = 1 To TabRow
- For jj = 1 To TabCol
- .Cell(Sss + ii, jj).Shape.TextFrame.TextRange.Text = DataArr(ii - 1, jj - 1)
- .Cell(Sss + ii, jj).Shape.TextFrame.TextRange.Font.Size = FontSize
- Next jj
- .Rows.Item(Sss + ii).Height = 1
- Next ii
-
- End With
- End Function
复制代码
|
|