2017-02-27 92 views
0

我爲高中學生製作了一個虛擬實驗室的幻燈片,偶爾有一張幻燈片向他們提問。他們可以在文本框中留下他們的答案。將PowerPoint中的特定幻燈片導出爲PDF格式

最後,我想插入一個包含宏的按鈕,該宏只會保存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。我已經看過關於這個話題的相關問題,但是我是一個如此大的noob,即使他們密切相關的例子我也無法解決我的問題。

+0

一個簡單的方法是保存當前演示文稿的臨時副本,向後退出幻燈片集合,刪除任何不符合條件的幻燈片,然後將結果保存爲PDF。 –

+0

@SteveRindsberg @SteveRindsberg這可以工作,但幻燈片的總數是350,所以這將是非常乏味的(特別是因爲大約20名學生完成作業,因此所有制作不同的文件)幻燈片數量如此之多,因爲有10個不同的幻燈片學生可以根據自己在作業中所做的工作路徑進行學習,學生必須組織不同的DNA元素並按照正確的順序進行排列,根據他們使用的順序,使用簡單的If textbox = ...然後查看幻燈片...所有其他路徑在賦值後變得不相關。 –

回答

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種不同的,並選擇幻燈片需要被保存爲每個路徑。

相關問題