|
楼主 |
发表于 2024-9-30 15:23
|
显示全部楼层
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
本帖最后由 zzpsx 于 2024-9-30 15:25 编辑
不一定吧。
请问这个文档里包含一段还是多段代码?
Sub test()
Dim r%, i%
Dim arr()
Dim pptApp As PowerPoint.Application
Dim pptPre As PowerPoint.Presentation
Application.ScreenUpdating = False
Application.DisplayAlerts = False
m = 0
With ThisDocument
For i = 1 To .Paragraphs.Count
ss = .Paragraphs(i).Range.Text
ss = Left(ss, Len(ss) - 1)
If Len(ss) <> 0 Then
m = m + 1
ReDim Preserve arr(1 To m)
arr(m) = Replace(.Paragraphs(i).Range.Text, Chr(13), "")
End If
Next
End With
If m = 0 Then
MsgBox "Word文件中没有数据!"
Exit Sub
End If
Set pptApp = New PowerPoint.Application
pptApp.Visible = msoTrue
Set pptPre = pptApp.Presentations.Add
With pptPre
For k = 1 To UBound(arr)
With .Slides.Add(Index:=.Slides.Count + 1, Layout:=ppLayoutTitleOnly)
ileft = (.CustomLayout.Width - 820) / 2
itop = (.CustomLayout.Height - 450) / 2
With .Shapes("Title 1")
.Left = ileft
.Top = itop
.Width = 820
.Height = 450
With .TextFrame
With .TextRange
.Text = arr(k)
With .Font
.Name = "等线(正文)"
.Size = 45
.Bold = True
End With
.ParagraphFormat.Alignment = 1
End With
End With
End With
End With
Next
.SaveAs Filename = ThisDocument.Path & "\结果"
' .Close
End With
' pptApp.Quit
' Set pptPre = Nothing
' Set pptApp = Nothing
Application.ScreenUpdating = True
MsgBox "幻片生成完毕!"
End Sub
|
|