Dim oApp As PowerPoint.Application
Dim oPres As PowerPoint.Presentation
????? ??? ??????Button1_Click?????:
Const sTemplate = "C:\Program Files\Microsoft Office\Templates\Presentation Designs\Orbit.pot"
' If the previous template is not available, change the template name to a template name that is on your system.
Const sVideo = "C:\WINDOWS\system32\oobe\images\intro.wmv"
Dim oPresentations As PowerPoint.Presentations
Dim oSlides As PowerPoint.Slides
Dim oSlide As PowerPoint.Slide
Dim oShapes As PowerPoint.Shapes
Dim oShape As PowerPoint.Shape
Dim oMovie As PowerPoint.Shape
Dim oAnimationSettings As PowerPoint.AnimationSettings
Dim oPlaySettings As PowerPoint.PlaySettings
Dim oTextFrame As PowerPoint.TextFrame
Dim oTextRange As PowerPoint.TextRange
Dim oFont As PowerPoint.Font
Dim oOLEFormat As PowerPoint.OLEFormat
Dim oShadow As PowerPoint.ShadowFormat
Dim oForeColor As PowerPoint.ColorFormat
Dim oRange As PowerPoint.SlideRange
Dim oSlideShowTransition As PowerPoint.SlideShowTransition
'Start PowerPoint and then make the PowerPoint window visible but minimized.
oApp = New PowerPoint.Application
'Add event handlers.
AddHandler oApp.SlideShowBegin, AddressOf oApp_SlideShowBegin
AddHandler oApp.SlideShowNextSlide, AddressOf oApp_SlideShowNextSlide
AddHandler oApp.PresentationClose, AddressOf oApp_PresentationClose
oApp.Visible = True
oApp.WindowState = PowerPoint.PpWindowState.ppWindowMinimized
'Create a new presentation that is based on the specified template.
oPresentations = oApp.Presentations
oPres = oPresentations.Open(sTemplate, , , True)
'Build slide 1.
'Add text to the slide, change the font, and then insert or position a
'movie on the first slide.
oSlides = oPres.Slides
oSlide = oSlides.Add(1, PowerPoint.PpSlideLayout.ppLayoutTitleOnly)
oShapes = oSlide.Shapes
oShape = oShapes.Item(1)
oTextFrame = oShape.TextFrame
oTextRange = oTextFrame.TextRange
oTextRange.Text = "My sample presentation"
oFont = oTextRange.Font
oFont.Name = "Comic Sans MS"
oFont.Size = 48
oMovie = oShapes.AddMediaObject(sVideo, 150, 150, 500, 350)
oAnimationSettings = oMovie.AnimationSettings
oPlaySettings = oAnimationSettings.PlaySettings
oPlaySettings.PlayOnEntry = True
oPlaySettings.HideWhileNotPlaying = True
'NAR to release references.
NAR(oPlaySettings)
NAR(oAnimationSettings)
NAR(oMovie)
NAR(oFont)
NAR(oTextRange)
NAR(oTextFrame)
NAR(oShape)
NAR(oShapes)
NAR(oSlide)
NAR(oSlides)
'Build slide 2.
'Add text to the slide title and then format the text. Also, add a chart to the
'slide and then change the chart type to a 3D Column Clustered.
oSlides = oPres.Slides
oSlide = oSlides.Add(2, PowerPoint.PpSlideLayout.ppLayoutTitleOnly)
oShapes = oSlide.Shapes
oShape = oShapes.Item(1)
oTextFrame = oShape.TextFrame
oTextRange = oTextFrame.TextRange
oTextRange.Text = "My chart"
oFont = oTextRange.Font
oFont.Name = "Comic Sans MS"
oFont.Size = 48
Dim oChart As Graph.Chart
oShape = oShapes.AddOLEObject(150, 150, 480, 320, "MSGraph.Chart.8")
oOLEFormat = oShape.OLEFormat
oChart = oOLEFormat.Object
oChart.ChartType = Graph.XlChartType.xl3DColumnClustered
'NAR to release references.
NAR(oChart)
NAR(oOLEFormat)
NAR(oFont)
NAR(oTextRange)
NAR(oTextFrame)
NAR(oShape)
NAR(oShapes)
NAR(oSlide)
NAR(oSlides)
'Build slide 3.
'Add a text effect to the slide and then apply shadows to the text effect.
oSlides = oPres.Slides
oSlide = oSlides.Add(3, PowerPoint.PpSlideLayout.ppLayoutBlank)
oSlide.FollowMasterBackground = False
oShapes = oSlide.Shapes
oShape = oShapes.AddTextEffect(Office.MsoPresetTextEffect.msoTextEffect27, _
"The End", "Impact", 96, False, False, 230, 200)
oShadow = oShape.Shadow
oForeColor = oShadow.ForeColor
oForeColor.SchemeColor = PowerPoint.PpColorSchemeIndex.ppForeground
oShadow.Visible = True
oShadow.OffsetX = 3
oShadow.OffsetY = 3
'NAR to release references.
NAR(oShadow)
NAR(oForeColor)
NAR(oShape)
NAR(oShapes)
NAR(oSlide)
NAR(oSlides)
'Modify the slide show transition settings for all three slides in
'the presentation.
Dim SlideIdx(3) As Integer
SlideIdx(0) = 1
SlideIdx(1) = 2
SlideIdx(2) = 3
oSlides = oPres.Slides
oRange = oSlides.Range(SlideIdx)
oSlideShowTransition = oRange.SlideShowTransition
oSlideShowTransition.AdvanceOnTime = False
oSlideShowTransition.EntryEffect = PowerPoint.PpEntryEffect.ppEffectBoxOut
'Run the slide show in a separate method.
RunSlideShow()
'NAR to release references.
NAR(oSlideShowTransition)
NAR(oRange)
NAR(oSlides)
'Close the presentation without saving changes and then quit PowerPoint.
oPres.Saved = True
oPres.Close()
'NAR the presentation objects.
NAR(oPres)
NAR(oPresentations)
'Remove all event handlers.
RemoveHandler oApp.SlideShowBegin, AddressOf oApp_SlideShowBegin
RemoveHandler oApp.SlideShowNextSlide, AddressOf oApp_SlideShowNextSlide
RemoveHandler oApp.PresentationClose, AddressOf oApp_PresentationClose
'Quit PowerPoint.
oApp.Quit()
NAR(oApp)
GC.Collect()
Private Sub RunSlideShow()
Dim oSettings As PowerPoint.SlideShowSettings
Dim oSlideShowWindows As PowerPoint.SlideShowWindows
oSettings = oPres.SlideShowSettings
oSettings.StartingSlide = 1
oSettings.EndingSlide = 3
'Run the slide show. Wait for the slide show to finish.
oSettings.Run()
oSlideShowWindows = oApp.SlideShowWindows
On Error Resume Next
Do While oSlideShowWindows.Count >= 1
System.Windows.Forms.Application.DoEvents()
Loop
NAR(oSlideShowWindows)
NAR(oSettings)
End Sub
'NAR function to remove reference.
Private Sub NAR(ByVal o As Object)
Try
System.Runtime.InteropServices.Marshal.ReleaseComObject(o)
Catch
Finally
o = Nothing
End Try
End Sub
????? ????? handlers ???? ????? ??? ??????:
'Event Handlers
Private Sub oApp_SlideShowBegin(ByVal Wn As Microsoft.Office.Interop.PowerPoint.SlideShowWindow)
'Change the position and the size of the slide show window.
Dim oView As PowerPoint.SlideShowView
With Wn
.Height = 325
.Width = 400
.Left = 100
.Activate()
End With
'Start the movie at the first slide.
oView = Wn.View
oView.Next()
NAR(oView)
NAR(Wn)
End Sub
Private Sub oApp_SlideShowNextSlide(ByVal Wn As Microsoft.Office.Interop.PowerPoint.SlideShowWindow)
'Change the color and the type of pointer depending on the slide.
Dim Showpos As Integer
Dim oView As PowerPoint.SlideShowView
Dim oColorFormat As PowerPoint.ColorFormat
oView = Wn.View
Showpos = oView.CurrentShowPosition + 1
If Showpos = 3 Then
oColorFormat = oView.PointerColor
oColorFormat.RGB = RGB(255, 0, 0)
oView.PointerType = PowerPoint.PpSlideShowPointerType.ppSlideShowPointerPen
Else
oColorFormat = oView.PointerColor
oColorFormat.RGB = RGB(0, 0, 0)
oView.PointerType = PowerPoint.PpSlideShowPointerType.ppSlideShowPointerArrow
End If
NAR(oColorFormat)
NAR(oView)
NAR(Wn)
End Sub
Private Sub oApp_PresentationClose(ByVal Pres As Microsoft.Office.Interop.PowerPoint.Presentation)
'Before you close the presentation, save the presentation as HTML.
Pres.SaveAs("C:\TestEvents.htm", PowerPoint.PpSaveAsFileType.ppSaveAsHTML)
NAR(Pres)
End Sub