Tuesday, September 25, 2012

Powerpoint Control using VB.NET

Here a sample application is developed that controls the next , previous actions of the Powerpoint

Steps
1.Create a new form with two Buttons (for VB)
2.Write the following code with the form

Imports System.Runtime.InteropServices
Imports Microsoft.Office.Interop.PowerPoint
Public Class Form1
    Dim oPP As Application
    Dim value As Presentation
    Dim hasopened As Boolean
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If (hasopened) Then
            Try
                oPP.ActivePresentation.SlideShowWindow.View.Next()
            Catch ex As Exception
                MsgBox(ex.Message)
            End Try
        End If
    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Try
            oPP = GetObject(, "PowerPoint.Application")
            hasopened = True
            value = oPP.ActivePresentation
        Catch ex As Exception
            MsgBox("No Presentations Opened")
            hasopened = False
            Me.Close()
        End Try
      
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        If (hasopened) Then
            Try
                oPP.ActivePresentation.SlideShowWindow.View.Previous()
            Catch ex As Exception
                MsgBox(ex.Message)
            End Try

        End If
    End Sub
End Class

Powerpoint control using vb.net

3.Open PPT,go to next,previous slides







Reference :
http://msdn.microsoft.com/en-us/library/ff763170.aspx

1 comment: