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

Opening HTML file in default Web Browser

Status
Not open for further replies.

arlequin

Programmer
Sep 21, 1999
232
UY
I've tried to open an HTML file using<br>
<br>
RetunrValue = Shell (&quot;IEXPLORE.EXE C:\TEMP\TEMP.htm&quot;)<br>
<br>
but it doesn't work porperly!!<br>
<br>
how can I open the browser associated with HTML pages?<br>
<br>

 
I have this, it might work for you...<br>
------------------------<br>
Dim FileName As String, Dummy As String<br>
Dim BrowserExec As String * 255<br>
Dim RetVal As Long<br>
Dim FileNumber As Integer<br>
Const SW_SHOWNORMAL = 1 ' Restores Window if Minimized or<br>
<br>
Declare Function ShellExecute Lib &quot;shell32.dll&quot; Alias &quot;ShellExecuteA&quot; _<br>
(ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, _<br>
ByVal lpParameters As String, ByVal lpDirectory As String, _<br>
ByVal nShowCmd As Long) As Long<br>
<br>
Declare Function FindExecutable Lib &quot;shell32.dll&quot; Alias &quot;FindExecutableA&quot; _<br>
(ByVal lpFile As String, ByVal lpDirectory As String, ByVal lpResult As _<br>
String) As Long<br>
'&lt;Code&gt; ---------<br>
<br>
BrowserExec = Space(255)<br>
FileName = &quot;C:\temphtm.HTM&quot;<br>
<br>
FileNumber = FreeFile() ' Get unused file number<br>
<br>
Open FileName For Output As #FileNumber ' Create temp HTML file<br>
Write #FileNumber, &quot; &lt;\HTML&gt;&quot; ' Output text<br>
Close #FileNumber ' Close file<br>
<br>
' Then find the application associated with it.<br>
RetVal = FindExecutable(FileName, Dummy, BrowserExec)<br>
BrowserExec = Trim$(BrowserExec)<br>
' If an application is found, launch it!<br>
If RetVal &lt;= 32 Or IsEmpty(BrowserExec) Then ' Error<br>
<br>
Msgbox &quot;Could not find a browser&quot;<br>
<br>
Else<br>
RetVal = ShellExecute(frmMain.hwnd, &quot;open&quot;, BrowserExec, _<br>
&quot;<A HREF=" TARGET="_new"> Dummy, SW_SHOWNORMAL)<br>
If RetVal &lt;= 32 Then ' Error<br>
Msgbox &quot;Web Page not Opened&quot;<br>
End If<br>
End If<br>
<br>
Kill FileName ' delete temp HTML file<br>
----------------------------------------<br>
On thing you must replace frmMain in the line<br>
RetVal = ShellExecute(frmMain.hwnd, .....<br>
to match your forms name or it won't work.<br>
<br>
<br>
<br>
<p> DougP<br><a href=mailto: dposton@universal1.com> dposton@universal1.com</a><br><a href= > </a><br>
 
MANY THANKS but I don't really understand why you give an URL as parameter if you want to open an HTML local file...<br>
<br>
I suppose that I must replace the URL with the file..¿?
 
Yep<br>
Some people just put generic references up. i.e.<br>
as in your case C:\TEMP\Temp.html<br>
<br>
I just tested the procedure before I posted it with our WEB site.<br>
<p> DougP<br><a href=mailto: dposton@universal1.com> dposton@universal1.com</a><br><a href= > </a><br>
 
OK, many tanx DougP!!<br>
<br>
I'll be trying your code as soon as I can !!<br>

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top