Hi.. Can somebody please advice me on how to set a powerpoint presentation as the powerpoint.application.activepresentation?

In the program below, when the form is loading, it will open 2 powerpoint files (Test1.ppt and Test2.ppt). After Test2.ppt is opened, it will be the activepresentation because it is opened last.

What I am trying to do is when I press button1, it will set Test1.ppt as activepresentation so that when I press button4, it will show me "C:\Test1.ppt".

The same also goes to button2 making Test2.ppt as activepresentation

But what I get is, no matter how many times i press button1, Test2.ppt is always the activepresentation.

Can somebody help me please.. Thanks.

Imports PowerPoint = Microsoft.Office.Interop.PowerPoint
Public Class Form1
    Dim oApp As New PowerPoint.Application
    Dim oPres As PowerPoint.Presentation
    Dim oSlide As PowerPoint.Slide
    Dim FileLocation1 As String = "C:\Test1.ppt"
    Dim FileLocation2 As String = "C:\Test2.ppt"
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        oApp = New PowerPoint.Application
        oApp.Visible = Microsoft.Office.Core.MsoTriState.msoTrue
        oPres = oApp.Presentations.Open(FileLocation1)
        oPres = oApp.Presentations.Open(FileLocation2)
    End Sub

'looping to get presentation index where the presentation's fullname match with FileLocation1
'Try to make Test1.ppt as activeapplication by using the index obtained
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim cntPres As Integer
        For cntPres = 1 To oApp.Presentations.Count
            If oApp.Presentations(cntPres).FullName = FileLocation1 Then
                oApp.Presentations(cntPres).Application.Activate()
                Exit For
            End If

        Next
    End Sub

'looping to get presentation index where the presentation's fullname match with FileLocation2
'Try to make Test2.ppt as activeapplication by using the index obtained
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Dim cntPres As Integer
        For cntPres = 1 To oApp.Presentations.Count
            If oApp.Presentations(cntPres).FullName = FileLocation2 Then
                oApp.Presentations(cntPres).Application.Activate()
                Exit For
            End If
        Next
    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        MsgBox(oApp.Presentations.Count.ToString)
    End Sub

    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        MsgBox(oApp.ActivePresentation.FullName)
    End Sub
End Class

Can somebody please advise me on this..?
If there is anything you guys are not sure about the questions, please do ask me and i'll try to explain more..
Thanks..

Oh.. by the way, this is not a homework ya..
I'm doing a program for my friend to automate powerpoint.. After i figure out how to do this part, i'll incorporate this code into the rest of the code.

Edited 6 Years Ago by mrnobody: n/a

This article has been dead for over six months. Start a new discussion instead.