Question

I'd like to create a button that automatically opens a hyperlink from Powerpoint.

It's easy enough to create a hyperlink in Powerpoint (Insert -> Hyperlink) and then click on that hyperlink.

I want to skip this whole process and just be able to have a button that opens a hyperlink rather than having a hyperlink in my presentation that needs to be clicked.

Was it helpful?

Solution

The XML for the button would be something like:

                    <button id="myButton" label="Open Hyperlink" 
                        imageMso="HyperlinkInsert"
                        size="large" 
                        onAction="openHyperlink"
                        />

Of course you will need to modify the file's Ribbon XML; the above is not a complete ribbon, just the node for the desired button. I have some other Q&A about modifying the ribbon here otherwise there are some great examples if you google for them. Most are for Word or Excel, but the same principles apply. If you need references, let me know and I can provide a few.

And the callback would be like:

Sub openHyperlink(control As IRibbonControl)
    'your code that opens the hyperlink goes in here, something like:
    Dim ie as Object
    Set ie = CreateObject("InternetExplorer.Application")
    ie.Visible = True
    ie.Navigate "http://google.com"

End Sub

To open a PDF instead of a browser, change that procedure:

Sub openHyperlink(control As IRibbonControl)

    Dim acroPath As String
    Dim filePath As String

    acroPath = "C:\Program Files (x86)\Adobe\Reader 10.0\Reader\AcroRd32.exe"  'Modify as needed
    filePath = "c:\users\me\file.pdf"  'Modify as needed

    Shell acroPath & " " & filePath, vbNormalFocus

End Sub

OTHER TIPS

You can use the ShellExecute API to open any document in the default app for that document's extension. Here's a simplified hack to start with:

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

Function ShellEx(sFile As String) As Long
    ShellEx = ShellExecute(&O0, "Open", sFile, "", "C:\", 1)
End Function

Sub Test()
    Debug.Print ShellEx("path to file goes here")
End Sub

More detailed version with all the options here: http://support.microsoft.com/kb/170918

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