Hi guys, how can I attach or link a file (an "HTML document") - a saved Web page...
that when I click a command button, the "HTML document" will be executed, just like double-clicking it in the explorer window.

Just view the attached image file for better understanding about my question, it's a screen shot..

I've been trying it out for 2 days, but i can't figure it out...

Sorry, for I'm just a newbie in VB 6...:(

Recommended Answers

Hi guys, how can I attach or link a file (an "HTML document") - a saved Web page...
that when I click a command button, the "HTML document" will be executed, just like double-clicking it in the explorer window.

Just view the attached image file for better understanding …

Jump to Post

if you want to shell and view in ie u must use shell with iexplorer address (C:\Program Files\Internet Explorer\iexplore.exe) and youe html file parameter (see shell on msdn) but if c:\ not default windows path u have problem to open ur file.
with windows api you can open all of …

Jump to Post

All 6 Replies

Hi guys, how can I attach or link a file (an "HTML document") - a saved Web page...
that when I click a command button, the "HTML document" will be executed, just like double-clicking it in the explorer window.

Just view the attached image file for better understanding about my question, it's a screen shot..

I've been trying it out for 2 days, but i can't figure it out...

Sorry, for I'm just a newbie in VB 6...:(

Use your shell command i.e.

Shell (c:/PoisenedHeart.html), vbNormalFocus

Make sure to have the path name correct and specify the window focus after comma.

if you want to shell and view in ie u must use shell with iexplorer address (C:\Program Files\Internet Explorer\iexplore.exe) and youe html file parameter (see shell on msdn) but if c:\ not default windows path u have problem to open ur file.
with windows api you can open all of filetype with origininal application like mydoc.doc window open with word mypdf.pdf open with acrobat,... every thing open in winodws you can open it.

another way u can use iframe control and develope new viewer for you self

Hi guys, how can I attach or link a file (an "HTML document") - a saved Web page...
that when I click a command button, the "HTML document" will be executed, just like double-clicking it in the explorer window.

Just view the attached image file for better understanding about my question, it's a screen shot..

I've been trying it out for 2 days, but i can't figure it out...

Sorry, for I'm just a newbie in VB 6...:(

Use your shell command i.e.

Shell (c:/PoisenedHeart.html), vbNormalFocus

Make sure to have the path name correct and specify the window focus after comma.

I have tried it, but I got this error:

Run-time error '5'
Invalid procedure call or argument

My code is this:

Private Sub Command1_Click()
    Shell App.Path & "\QuizThing.html", vbNormalFocus
End Sub

You can view the screenshot....

Here's the full code. This works on my side. Copy and paste into your form module.

Option Explicit

Private Declare Function GetDesktopWindow Lib "user32" () As Long

Private Const SW_SHOWNORMAL As Long = 1
Private Const SW_SHOWMAXIMIZED As Long = 3
Private Const SW_SHOWDEFAULT As Long = 10

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()

   Dim sTopic As String
   Dim sFile As String
   Dim sParams As String
   Dim sDirectory As String

  'set default setting to be used
  'if not specifically required
   sTopic = "Open"
   sFile = vbNullString
   sParams = vbNullString
   sDirectory = vbNullString
              
sFile = App.Path & "\QuizThing.html"

   
Call RunShellExecute(sTopic, sFile, sParams, sDirectory, SW_SHOWDEFAULT)
   
End Sub

Private Sub RunShellExecute(sTopic As String, sFile As Variant, sParams As Variant, sDirectory As Variant, nShowCmd As Long)

   Dim success As Long
Dim hWndDesk As Long
  
  'the desktop will be the
  'default for error messages
   hWndDesk = GetDesktopWindow()
  
  'execute the passed operation
   success = ShellExecute(hWndDesk, sTopic, sFile, sParams, sDirectory, nShowCmd)

  'This is optional. Uncomment the three lines
  'below to have the "Open With.." dialog appear
  'when the ShellExecute API call fails
  If success < 32 Then
     Call Shell("rundll32.exe shell32.dll,OpenAs_RunDLL " & sFile, vbNormalFocus)
  End If
   
End Sub

You'll see at the end there is an error trap. This will open the 'Open With' dialog box if your html document is not found or any other error occurs.

Here's the full code. This works on my side. Copy and paste into your form module.

Option Explicit

Private Declare Function GetDesktopWindow Lib "user32" () As Long

Private Const SW_SHOWNORMAL As Long = 1
Private Const SW_SHOWMAXIMIZED As Long = 3
Private Const SW_SHOWDEFAULT As Long = 10

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()

   Dim sTopic As String
   Dim sFile As String
   Dim sParams As String
   Dim sDirectory As String

  'set default setting to be used
  'if not specifically required
   sTopic = "Open"
   sFile = vbNullString
   sParams = vbNullString
   sDirectory = vbNullString
              
sFile = App.Path & "\QuizThing.html"

   
Call RunShellExecute(sTopic, sFile, sParams, sDirectory, SW_SHOWDEFAULT)
   
End Sub

Private Sub RunShellExecute(sTopic As String, sFile As Variant, sParams As Variant, sDirectory As Variant, nShowCmd As Long)

   Dim success As Long
Dim hWndDesk As Long
  
  'the desktop will be the
  'default for error messages
   hWndDesk = GetDesktopWindow()
  
  'execute the passed operation
   success = ShellExecute(hWndDesk, sTopic, sFile, sParams, sDirectory, nShowCmd)

  'This is optional. Uncomment the three lines
  'below to have the "Open With.." dialog appear
  'when the ShellExecute API call fails
  If success < 32 Then
     Call Shell("rundll32.exe shell32.dll,OpenAs_RunDLL " & sFile, vbNormalFocus)
  End If
   
End Sub

You'll see at the end there is an error trap. This will open the 'Open With' dialog box if your html document is not found or any other error occurs.

Wow!!,,..What a code....
Thank you for your time for doing these codes...

Hope this will solve my problem....

A BIG Thanks to you!
:icon_smile:

Only a pleasure. Please mark as answered if it works for you. You are also welcome to add to my reputation should you feel so.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.19 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.