【发布时间】:2016-03-11 03:24:11
【问题描述】:
目前我在 PowerPoint 上有一个宏,可以在 PowerPoint 文件中查找关键字并将包含关键字的幻灯片保存为 JPEG 文件。但是,我注意到由于代码贯穿每个形状,它会在找到幻灯片中的每个关键字之前保存文件,因此创建了许多具有相同幻灯片页面但每次突出显示一个关键字的 JPEG 文件,有什么办法可以在幻灯片上找到每个关键字后,让宏打印一张幻灯片?
代码:
Option Explicit
Sub fgdg()
Dim sImagePath As String
Dim sImageName As String
Dim lScaleWidth As Long '* Scale Width
Dim lScaleHeight As Long '* Scale Height
Dim sld As Slide
Dim shp As Shape
Dim txtRng As TextRange, rngFound As TextRange
Dim i As Long, n As Long
Dim TargetList
On Error GoTo Err_ImageSave
'~~> EDIT THE ITEMS IN THE ARRAY() TO FIND DESIRED WORD(S)
TargetList = Array("doodle")
'~~> Loop through each slide
For Each sld In Application.ActivePresentation.Slides
'~~> Loop through each shape
For Each shp In sld.Shapes
'~~> Check if it has text
If shp.HasTextFrame Then
Set txtRng = shp.TextFrame.TextRange
sImagePath = "D:/"
For i = 0 To UBound(TargetList)
'~~> Find the text
Set rngFound = txtRng.Find(TargetList(i))
'~~~> If found
Do While Not rngFound Is Nothing
'~~> Set the marker so that the next find starts from here
n = rngFound.Start + 1
'~~> Change attributes
With rngFound.Font
.Bold = msoTrue
.Underline = msoTrue
.Italic = msoTrue
.Color.RGB = RGB(255, 255, 0)
sImageName = rngFound.Start & ".jpg"
sld.Export sImagePath & sImageName, "JPG"
'~~> Find Next instance
Set rngFound = txtRng.Find(TargetList(i), n)
End With
Loop
Next
End If
Next
Next
Err_ImageSave:
If Err <> 0 Then
MsgBox Err.Description
End If
End Sub
【问题讨论】:
标签: vba powerpoint