hi,
how can i run a file such as helloworld.html with its default viewer after i click a cmdButton or some how in the code ...
Printable View
hi,
how can i run a file such as helloworld.html with its default viewer after i click a cmdButton or some how in the code ...
use shellExecute api
Code:'open a file with associated app can be done this way [using API]
'open a file with it's associated application
'this example opens an mp3 file with winamp
'put this in a bas module
'
Public Declare Function ShellEx Lib "shell32.dll" Alias _
"ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, _
ByVal lpFile As String, ByVal lpParameters As Any, _
ByVal lpDirectory As Any, ByVal nShowCmd As Long) As Long
'
Sub ShellDef(strFileName)
x = ShellEx(Form1.hwnd, "open", strFileName, "", "", 1)
End Sub
'this goes in your form
Private Sub Command1_Click()
' >>> code for event on form <<<
'
Dim strYourFileVariable$
strYourFileVariable = "c:\myfolder\myFile.mp3"
ShellDef strYourFileVariable
'=====================================
End Sub
Copy into a Module:
then copy this into your form:Code: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 Const SW_SHOWNORMAL = 1
Hope that helps!Code:Public Sub Link2Net(AddUrl As String)
Dim iloc As Long
iloc = ShellExecute(Me.hwnd, vbNullString, AddUrl, vbNullString, "c:\", SW_SHOWNORMAL) 'Me.hwnd or formname.hwnf
End Sub
Private Sub Command1_Click()
Call Link2Net(Text2.Text) ' I used a textbox for the url but just put the url inplace ("http://www.whatever.com")
End Sub
i had try both of the code shown .... nothing happen when i try to open html file type (offline) ...??
Try shelling IE directly with the file as the command line.
Code:Shell "C:\Program Files\Internet Explorer\IExplore.exe C:\OfflineFile.htm", vbNormalFocus
[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
Private Sub Command1_Click()
ShellExecute hwnd, "open", "helloworld.html", "", "", 1
End Sub
sorry, is my mistake. all the code work perfectly ... thank!!