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

lbour

New Member
Joined
Nov 21, 2005
Messages
34
Office Version
  1. 365
Platform
  1. Windows
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
+++++++++++++++++++++++++++
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
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
 
Upvote 0
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
 
Upvote 0

Forum statistics

Threads
1,214,945
Messages
6,122,395
Members
449,081
Latest member
JAMES KECULAH

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
Back
Top