|
楼主 |
发表于 2019-11-2 09:29
|
显示全部楼层
简单写了个测试的,还在完善,基本可以搞起来了
- Set ppt = VBA.CreateObject("powerpoint.application")
- With ppt
- .Visible = msoTrue
- Dim pReport
- If .presentations.Count > 0 Then
- Set pReport = .presentations(1)
- Else
- Set pReport = .presentations.Add(True)
- pReport.Slides.Add 1, 12
- pReport.SaveAs "a1.pptx"
- End If
- 'deal with word
- pcount = ActiveDocument.Paragraphs.Count
- For i = 1 To pcount
- If ActiveDocument.Paragraphs(i).OutlineLevel = wdOutlineLevel2 Then
- Debug.Print (ActiveDocument.Paragraphs(i).Range.Text)
- Call addPPT(ActiveDocument.Paragraphs(i).Range.Text, pReport)
- End If
- Next
-
- For i = 1 To pcount
- If ActiveDocument.Paragraphs(i).OutlineLevel = wdOutlineLevel3 Then
- Debug.Print (ActiveDocument.Paragraphs(i).Range.Text)
- Call addPPT(ActiveDocument.Paragraphs(i).Range.Text, pReport)
- pWords = ActiveDocument.Paragraphs(i + 1).Range.Words.Count
- For j = 1 To pWords
- Debug.Print (ActiveDocument.Paragraphs(i + 1).Range.Words(j).Text)
- If ActiveDocument.Paragraphs(i + 1).Range.Words(j).Font.Underline = wdUnderlineSingle Then
- Debug.Print (ActiveDocument.Paragraphs(i + 1).Range.Words(j).Text)
- Call addPPT(ActiveDocument.Paragraphs(i + 1).Range.Words(j).Text, pReport)
- End If
- Next
- End If
- Next
- 'end deal with word
复制代码- Function addPPT(ByRef content, ByRef pReport)
- With pReport
- Dim oSlide
- cSlide = .Slides.Count
- If cSlide > 0 Then
- pReport.Slides.Add cSlide + 1, 12
- Set oSlide = .Slides(cSlide + 1)
- Set ptShape = oSlide.Shapes.AddTextbox(Orientation:=msoTextOrientationHorizontal, _
- Left:=10, Top:=17, Width:=300, Height:=50)
- With ptShape.TextFrame
- .TextRange.Font.Name = "方正小标宋简体"
- .TextRange.Text = content
- .TextRange.Font.Size = 30
- .TextRange.Font.Bold = True
- .TextRange.Font.Color.RGB = RGB(Red:=255, Green:=0, Blue:=0)
- End With
- Else
- Set oSlide = .Slides.Add(1, ppLayoutBlank)
- Set ptShape = oSlide.Shapes.AddTextbox(Orientation:=msoTextOrientationHorizontal, _
- Left:=10, Top:=17, Width:=30, Height:=50)
- With ptShape.TextFrame
- .TextRange.Text = "mfb"
- .TextRange.Font.Name = "楷体_GB2312"
- .TextRange.Font.Size = 30
- .TextRange.Font.Bold = True
-
- End With
- End If
- End With
- End Function
复制代码
|
|