VBA Code to open PowerPoint Presentation

Sillsc0417

New Member
Joined
Oct 2, 2014
Messages
17
Good morning! I have placed the following code in excel to open up a powerpoint presentation and it works... to a certain point. It opens up the presentation; however, it will not make it the active screen. It opens it in the system tray and I see the Powerpoint Icon flashing, but will not activate the screen and bring it to the forefront. Problem is that it leaves quite a bit of my inexperienced users thinking that the button didn't open the presentation at all.. Any ideas?

Sub Button657_Intel()
Dim objPPT As Object
Set objPPT = CreateObject("PowerPoint.Application")
objPPT.Visible = True
objPPT.Presentations.Open "H:\Test.pptx"
End Sub
 

Some videos you may like

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.

ranman256

Well-known Member
Joined
Jun 17, 2014
Messages
1,900
Ditch that code and try this. It will open ANY APP. If you give it a powerpoint file, powerpoint opens. If you give it a .doc, MsWord will open.
Put this code in a module and
usage: OpenNativeApp "c:\fodler\myfile.ppt"


Code:
'Attribute VB_Name = "modNativeApp"
Option Compare Database
Option Explicit
Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpszOp As String, ByVal lpszFile As String, ByVal lpszParams As String, ByVal lpszDir As String, ByVal FsShowCmd As Long) As Long
Private Declare Function GetDesktopWindow Lib "user32" () As Long
Const SW_SHOWNORMAL = 1
Const SE_ERR_FNF = 2&
Const SE_ERR_PNF = 3&
Const SE_ERR_ACCESSDENIED = 5&
Const SE_ERR_OOM = 8&
Const SE_ERR_DLLNOTFOUND = 32&
Const SE_ERR_SHARE = 26&
Const SE_ERR_ASSOCINCOMPLETE = 27&
Const SE_ERR_DDETIMEOUT = 28&
Const SE_ERR_DDEFAIL = 29&
Const SE_ERR_DDEBUSY = 30&
Const SE_ERR_NOASSOC = 31&
Const ERROR_BAD_FORMAT = 11&

Public Sub OpenNativeApp(ByVal psDocName As String)
Dim r As Long, msg As String
r = StartDoc(psDocName)
If r <= 32 Then
    'There was an error
    Select Case r
        Case SE_ERR_FNF
            msg = "File not found"
        Case SE_ERR_PNF
            msg = "Path not found"
        Case SE_ERR_ACCESSDENIED
            msg = "Access denied"
        Case SE_ERR_OOM
            msg = "Out of memory"
        Case SE_ERR_DLLNOTFOUND
            msg = "DLL not found"
        Case SE_ERR_SHARE
            msg = "A sharing violation occurred"
        Case SE_ERR_ASSOCINCOMPLETE
            msg = "Incomplete or invalid file association"
        Case SE_ERR_DDETIMEOUT
            msg = "DDE Time out"
        Case SE_ERR_DDEFAIL
            msg = "DDE transaction failed"
        Case SE_ERR_DDEBUSY
            msg = "DDE busy"
        Case SE_ERR_NOASSOC
            msg = "No association for file extension"
        Case ERROR_BAD_FORMAT
            msg = "Invalid EXE file or error in EXE image"
        Case Else
            msg = "Unknown error"
    End Select
'    MsgBox msg
End If
End Sub
Private Function StartDoc(psDocName As String) As Long
Dim Scr_hDC As Long
Scr_hDC = GetDesktopWindow()
StartDoc = ShellExecute(Scr_hDC, "Open", psDocName, "", "C:\", SW_SHOWNORMAL)
End Function
 

Sillsc0417

New Member
Joined
Oct 2, 2014
Messages
17
Wow.. that's quite a bit.. I'm a relatively inexperienced excel coder.. so forgive me if I sound like I have no idea... but, the goal of the code I had originally was to give users a button interface on a spreadsheet and when they execute a particular button, it launches a powerpoint training presentation for users to view.. the code that you have provided me with... I get that it belongs in a module, but I'm lost as to how it actually will work..the presentation only needs to launch upon user activation of the button... can you help me with a brief explanation of how your code works?
 

Watch MrExcel Video

Forum statistics

Threads
1,109,033
Messages
5,526,368
Members
409,697
Latest member
christopherlewis1620

This Week's Hot Topics

Top