我为高中学生设立了一个虚拟实验室,偶尔有一张幻灯片可以向他们提问。他们可以将答案留在文本框中。
最后,我想插入一个包含宏的按钮,该宏只会将存在问题的幻灯片保存到PDF文件中。其他幻灯片与老师无关。
简而言之:我正在尝试创建一个PowerPoint宏,我可以将选择的幻灯片保存为PDF。它不是一系列幻灯片,而是一系列幻灯片。
目前我有这个:
Private Sub CommandButton2_Click()
Dim mySlides As Variant
Dim PR As PrintRange
Dim savePath As String
Dim myInput As String
'Add the name of the student in the file name
myInput = ActivePresentation.Slides(1).Shapes("TextBox2").OLEFormat.Object.Text
'Location of saved file
savePath = ActivePresentation.Path & "\" & myInput & " Antwoorden Virtueel Lab" & ".pdf"
If ActivePresentation.Slides(9).Shapes("TextBox1").OLEFormat.Object.Text = "PRARDT" Then
mySlides = Array(9, 11, 15)
Set PR = ActivePresentation.Slides.Range(mySlides)
ActivePresentation.ExportAsFixedFormat _
Path:=savePath, _
FixedFormatType:=ppFixedFormatTypePDF, _
PrintRange:=PR, _
Intent:=ppFixedFormatIntentScreen, _
FrameSlides:=msoTrue, _
RangeType:=ppPrintSlideRange
Else: MsgBox "Does not work"
End If
End Sub
然而它不起作用
如果我想使用一系列幻灯片,我可以使用此代码(这确实有效):
Private Sub CommandButton3_Click()
'This function saves the last slide as a PDF file with a time stamp and the users name who completed the induction.
Dim PR As PrintRange
Dim savePath As String
Dim myInput As String
myInput = ActivePresentation.Slides(1).Shapes("TextBox2").OLEFormat.Object.Text
'Location of saved file
savePath = ActivePresentation.Path & "\" & myInput & " Antwoorden Virtueel Lab" & ".pdf"
If ActivePresentation.Slides(9).Shapes("TextBox1").OLEFormat.Object.Text = "PRARDT" Then
With ActivePresentation.PrintOptions
.Ranges.ClearAll ' always do this
Set PR = .Ranges.Add(9, 21)
End With
ActivePresentation.ExportAsFixedFormat _
Path:=savePath, _
FixedFormatType:=ppFixedFormatTypePDF, _
PrintRange:=PR, _
Intent:=ppFixedFormatIntentScreen, _
FrameSlides:=msoTrue, _
RangeType:=ppPrintSlideRange
Else
MsgBox "something went wrong"
End If
End Sub
此宏确实有效,但我只能用它或1张特定幻灯片打印一系列幻灯片。我想打印一个特定幻灯片数组到PDF。我已经看过关于这个主题的相关问题但是我是一个如此大的菜鸟,即使用他们密切相关的例子也无法解决我的问题。
答案 0 :(得分:0)
我做到了!我终于找到了错误的来源,现在有了一个有效的宏
Private Sub CommandButton4_Click()
Dim myInput As String
Dim savePath As String
'Name of Student
myInput = ActivePresentation.Slides(1).Shapes("TextBox2").OLEFormat.Object.Text
'Location of saved file
savePath = ActivePresentation.Path & "\" & myInput & " Antwoorden Virtueel Lab" & ".pdf"
'Select path student took
If ActivePresentation.Slides(9).Shapes("TextBox1").OLEFormat.Object.Text = "PRARDT" Then
'Change view
ActivePresentation.SlideShowWindow.View.Exit
'Prevents error
ActiveWindow.Panes(1).Activate
'Select specific slides
ActivePresentation.Slides.Range(Array(9, 11, 15)).Select
'save selected slides as PDF
ActivePresentation.ExportAsFixedFormat Path:=savePath, FixedFormatType:=ppFixedFormatTypePDF, RangeType:=ppPrintSelection
MsgBox "file saved"
Else
MsgBox "wont work"
End If
End Sub
现在我将制作9个不同的,然后选择需要为每个路径保存哪些幻灯片。