Can a Macro launch a PDF file? If not, a Windows Directory?

lbour

New Member
Joined
Nov 21, 2005
Messages
31
Thru wonderful suggestions I found on the forum, I was able to create a macro to launch Word documents. I use a combo box to call the macro, and it works fine.

However, the group that creates the report has changed the format, and now creates it as a PDF instead of a .doc file.

Can a macro be used to open a PDF?

Here is the code I am using to open the Word docs. I was hoping to add something to this, if at all possible.

So my code makes sense, each month's worth of reports are stored in a different directory. My 'range' references help identify the appropriate directory. I included a Msg box so any staff member who selects a report in a month that includes the new .pdf format will understand why they don't get their report. Darn department, this thing worked well until they changed formats!!

Any help and all suggestions are greatly appreciated!
Kind regards,
Lee

ps: If a macro can't open a .pdf, can it open a directory window? I'm thinking that if the .pdf idea doesn't work, they can still click a button to open a directory window so they can manually select a month-specific sub-directory and then double-click on the daily report they are interested in.

+++++++++++++++++++++
Sub opendoc()

Dim valMonth
Dim valPubDate
Dim valDir
Dim strFilename As String
Dim strPath As String

Set appWD = CreateObject("Word.Application")

valMonth = Sheets("control").Range("D32")
valPubDate = Sheets("control").Range("H37")
valDir = Sheets("control").Range("D46")

strPath = "T:\Corporate Marketing\" & valDir & "\"
strFilename = valPubDate

If valMonth > 1 And valMonth < 7 Then
appWD.Documents.Open Filename:=strPath & strFilename
appWD.Visible = True
ElseIf valMonth > 6 Then
MsgBox "Cannot accesss PDF Files. Working on a Fix."
End If

End Sub
+++++++++++++++++++++++++++
 

Some videos you may like

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.

NateO

Legend
Joined
Feb 17, 2002
Messages
9,700
Hello,

ShellExecute() or Shell() can do both. See the following:

http://www.mrexcel.com/board2/viewtopic.php?p=1310030#1310030

;)

Edit: Here's an example of ShellExecute():

Code:
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

Sub foo()
Call ShellExecute(0, "Open", "Adobe File.pdf", vbNullString, _
    "C:\Temp", 0)
End Sub
 

lbour

New Member
Joined
Nov 21, 2005
Messages
31
Hi NateO,

Thanks for the suggestion! I've looked back at your links... and your suggestions to Markus. Don't think I understand it all, but that's my job to figure it out. Or... at least try to. :)

I may come back to you if I get stuck.

Thanks again,
Lee
 

Watch MrExcel Video

Forum statistics

Threads
1,122,670
Messages
5,597,480
Members
414,143
Latest member
lonnie451

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top