LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 860
Default Can I run an external program?

Hi Dick,

Dick Kusleika wrote:
I'd like to be able have a routine that launches a PDF file. The
closest thing I can find it the ActivateMicrosoftApp Method which, of
course doesn't work with the Adobe product files.


Consider using the FollowHyperlink method. It will open the file
according to your Windows associations. See

http://www.dicks-blog.com/archives/2...nt-file-types/


Personally, I don't like using the FollowHyperlink method for anything but
URLs. On my machine (Win XP SP2), I get a warning telling me that links may
harm my computer.

Here's a way to do it with the API, which is cleaner and gives you more
options on how you want to display the document and what to do if it's not
found:

Public Const SW_SHOWMAXIMIZED = 3
Public Const ERROR_FILE_NOT_FOUND = 2&

Public 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

Public Function gbOpenDocument(rsFullPath As String, _
rsErrMsg As String) As Boolean
Dim lResponse As Long

lResponse = ShellExecute(Application.hwnd, _
"open" & vbNullChar, rsFullPath & vbNullChar, _
vbNull, vbNull, SW_SHOWMAXIMIZED)

If lResponse = ERROR_FILE_NOT_FOUND Then rsErrMsg _
= "File not found."
gbOpenDocument = (lResponse 32)
End Function

Sub test()
Dim sErr As String

Debug.Print gbOpenDocument("c:\test234.pdf", sErr)
If Len(sErr) Then Debug.Print sErr
End Sub

--
Regards,

Jake Marx
MS MVP - Excel
www.longhead.com

[please keep replies in the newsgroup - email address unmonitored]



 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to pass a cell as parameter for an external program? maxbell Excel Discussion (Misc queries) 1 February 8th 07 10:40 AM
Copying data to an external Program Debby Bunce New Users to Excel 1 June 9th 05 12:31 AM
How do I run an external program? Phillips Excel Programming 1 November 25th 03 05:23 PM
Open external program bondy Excel Programming 1 October 22nd 03 01:57 PM
starting an external program with a command line Jonathan[_5_] Excel Programming 0 September 5th 03 02:20 PM


All times are GMT +1. The time now is 01:19 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"