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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Opening a file 3

Status
Not open for further replies.

Edge118

Programmer
Jun 15, 2004
104
0
0
US
If I have a text file at the location "c:\hello.txt" how can I have my VB program open it (as if I double clicked on it) during execution?

Thanks for helping.

"Pin me. Perl me."

Regards,

Chris
 
Call Shell("Notepad c:\hello.txt", vbNormalFocus)

-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
or:

Shell "Notepad c:\hello.txt", vbNormalFocus

or if you want to use the default app to open the document (any document!)

Shell "RUNDLL32.EXE URL.DLL,FileProtocolHandler c:\hello.txt" , vbNormalFocus


________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first
'If we're supposed to work in Hex, why have we only got A fingers?'
Essex Steam UK for steam enthusiasts
 
The benefits of ShellExecute are that it will open the file with whatever default is associated with the extension of the chosen file, and it also allows spaces in the path of the parameters.

Code:
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 Const SW_HIDE As Long = 0
Private Const SW_SHOWNORMAL As Long = 1

Private Sub Command1_Click()
    ShellExecute 0&, "OPEN", "c:\hello.txt", vbNullString, "C:\", SW_SHOWNORMAL
 
 ' c:\ = Destination Folder
End Sub

David
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top