我为我的计算机类创建了第一个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 :(得分: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)
如果您在键入内容时使用intellisense,请注意,如果您向Shapes(2)
添加索引,则AddShape
不是一个选项,但如果您只使用Shapes.
,那么{{ 1}}是一种有效的方法。