Question

Hello i'm trying to make a program for my friend that will launch PowerPoint in slideshow mode. It works by typing in a name into a textbox and then add the rest for the user. The problem is that it always fails finding the target and I need some help.

Could somebody review the code and fix the problem(s)?

Also keep it simple for the user please.

Public Class Form1

Dim fileName As String
Dim filePath As String
Dim Command As String = Chr(34) + "C:\Program Files\Microsoft Office\Office14\POWERPNT.EXE\" + Chr(34) + " /S "

Sub Run()
    Try
        filePath = (Command + "powerpoints\" + fileName + ".pptx")
        Process.Start(filePath)

    Catch ex As Exception
        Beep()
        MessageBox.Show(ex.Message, "Error!")
    End Try
End Sub

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    fileName = TextBox1.Text
    Run()
End Sub
End Class
Was it helpful?

Solution

2 suggestions. First, are you received any exception when you run this code? If so, can you please post those details? If possible, debug and step through the code to determine what line the code is failing on. That will help determine what "target" is failing.

Secondly, if you're walking blindly on some of this code, try checking out some other examples online (if you haven't already). A quick Google on this topic provided this (courtesy of http://officeone.mvps.org/vba/vb_start_slide_show.html)

Sub StartSlideShow(ByVal FileName  As String)
     Dim PPT  As Object
     Dim Pres  As Object

     On Error Resume Next

     Set PPT = CreateObject("PowerPoint.Application")
     Set Pres = PPT.Presentations.Open(FileName, False, False,  False)
     If Pres.SlideShowWindow  Is Nothing Then
         Pres.SlideShowSettings.Run
     End If
End Sub 

It seems relatively straightforward, so hopefully it points you in the right direction.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top