Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Open a file with its associated program? 2

Status
Not open for further replies.

Ham

Technical User
Feb 23, 2000
122
US
I generate a .txt log file in a VBA application. At the end, I give the user the option to view it now. To display it, I search for notepad.exe and display the log file via the SHELL command. Unfortunately, one of the machines on which this program runs does not have notepad on it. Is there any way to display a file using whatever program the host computer has associated with .txt files? (This would be the VBA equivalent of double-clicking on the file.)

Many thanks. -- Ham Rutledge
 
There is a "ShellExecute" command, and I believe you can find info on how to program using it in Microsoft's knowledgebase at
However, I find it much easier just to use hyperlinks. For example, I have the following code in one of my programs:

Public Function MBR_All_PDFManual()
On Error GoTo Err_MBR_All_PDFManual

Dim strAddress As String

strAddress = "\\Candylan\Vol1\...\whatever.pdf"
' Original path deleted from this example for
' corporate security reasons


Application.FollowHyperlink strAddress

Exit_MBR_All_PDFManual:
Exit Function

Err_MBR_All_PDFManual:
MsgBox Err.Description, , "MBR_All_PDFManual: " & Err.Number
Resume Exit_MBR_All_PDFManual
End Function


This opens the PDF file with Acrobat or Acrobat reader, whichever is the default PDF reader, regardless of where it is installed on the machine.

Hope that helps..
Katie
 
Katie - Thank you very much. I used your hyperlink approach and it was exactly what I was looking for. Thanks again. -- Ham
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top