2014-03-19 117 views
0

我爲我的計算機課程創建了我的第一個VBA測驗,需要打印結果。與我在網上找到的幾個模型相比,我粘貼了PrintablePage和PrintResults。請告訴我哪裏出錯了。結果頁面正確顯示,但打印按鈕不起作用。爲什麼我的幻燈片不打印

Sub PrintablePage() 
Dim printableSlide As Slide 
Dim printbutton As Shape 
Dim donebutton As Shape 

Set printableSlide = ActivePresentation.Slides.Add(Index:=8, Layout:=ppLayoutText) 
printableSlide.Shapes(1).TextFrame.TextRange.Text = "Test results for " & Username 
printableSlide.Shapes(2).TextFrame.TextRange.Text = "You got " & numberRight & " out of " & _ 
numberRight + numberWrong & "." & Chr$(13) & "Please press print." 

Set donebutton = ActivePresentation.Slides(8).Shapes.AddShape(msoShapeActionButtonCustom, 0, 0, 150, 50) 
donebutton.TextFrame.TextRange.Text = "Close Program" 
donebutton.ActionSettings(ppMouseClick).Action = ppActionRunMacro 
donebutton.ActionSettings(ppMouseClick).Run = "done" 

Set printbutton = ActivePresentation.Slides(8).Shapes(2).AddShape(msoShapeActionButtonCustom, 400, 400, 100, 100) 
printbutton.TextFrame.TextRange.Text = "Print" 
printbutton.ActionSettings(ppMouseClick).Action = ppActionRunMacro 
printbutton.ActionSettings(ppMouseClick).Run = "PrintResults" 
ActivePresentation.SlideShowWindow.View.Next 
ActivePresentation.Saved = True 
End Sub 

Sub PrintResults() 
donebutton.Visible = False 
printbutton.Visible = False 
ActivePresentation.PrintOptions.OutputType = ppPrintOutputSlides 
ActivePresentation.PrintOut From:=8, To:=8 
donebutton.Visible = True 
printbutton.Visible = True 
End Sub 

Sub done() 
MsgBox "The program will shut down now" 
ActivePresentation.Slides(8).Delete 
ActivePresentation.Saved = msoCTrue 
ActivePresentation.Application.Quit 
End Sub 

任何幫助將不勝感激。

+0

我甚至不知道2從哪裏來的,可能是因爲我試過了我能找到的每一個。無論如何,我不會 – Bernadette

+0

@portlandrunner感謝您的幫助。我甚至不知道這2個來自哪裏,可能是因爲我試過了我能找到的每一個。無論如何,我沒有2我的,它仍然不會打印。帶結果的可打印頁面,沒問題。關閉時刪除結果頁面,沒問題。但是打印......沒有任何工作。我比較的每個樣本都是一樣的,當然除了幻燈片索引。這太令人沮喪了,但令人興奮,這對我來說是一個很好的謎! – Bernadette

回答

1

您正試圖將形狀添加到現有的索引。 PowerPoint不允許這樣做。

變化:

Set printbutton = ActivePresentation.Slides(8).Shapes(2).AddShape(msoShapeActionButtonCustom, 400, 400, 100, 100) 

要:

Set printbutton = ActivePresentation.Slides(8).Shapes.AddShape(msoShapeActionButtonCustom, 400, 400, 100, 100) 

如果使用智能感知在鍵入時,你會發現,如果你添加一個索引來Shapes(2)然後AddShape是不是一種選擇,而是如果你只使用Shapes.那麼AddShape是一個有效的方法。

相關問題