PDA

View Full Version : Word Macro to Open PDF



CWT
11-27-2013, 10:07 AM
I have a drop down menu that I have created in Word which I would like to attach macro's to. Each macro will point to a different PDF file, so when the user clicks the menu option it will open the specific PDF.I have found the code below. It seems to work, but when I go to try and attach it it is not in my list of macro's. How do I get it to show in my list. Will I need to create a new module for each PDF macro if I use the below code? What I would like is one module, but the code repeated and only the file path for each macro will be changed. Hope that make sense. Option Explicit Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" ( _ ByVal hwnd As Long, _ ByVal lpOperation As String, _ ByVal lpFile As String, _ ByVal lpParameters As String, _ ByVal lpDirectory As String, _ ByVal nShowCmd As Long) As Long Private Sub Document_Open() ShellExecute 0&, "open", "C:\SomeFile.pdf", vbNullString, "C:\", 1 End Sub

macropod
11-28-2013, 02:10 PM
Hi CWT,

When posting code, please use the code tags. They're on the 'Go Advanced' tab. Without them your code has all been mugged together and is much more difficult to decipher than it need be.

Two comments about your code:
1. The macro is a Document_Open macro, which would normally go in the 'ThisDocument' module of the document or its template and would fire automatically every time the document is opened; in other words, your 'C:\SomeFile.pdf' file would be processed every time you open the document. Do you really want that?
2. The reason the macro doesn't appear in the macro list is that it is prefixed with 'Private'.