Opening a specific page in IE through VB

codingmasters
How do you open a specififc page in Internet Explorer through Visual Basic 6?

And just for you Ste, I've already tried this question on vbforums.com and no-one answered my post

Matthew G.

Anonymous

How do you open a specififc page in Internet Explorer through Visual Basic 6?



it's not really a good idea to assume that everyone wants to use IE (even if they do have it by default) what you ought to do is open a specific page in whatever browser the individual has chosen.

(If you insist on doing it in IE - look up the SHELL command in VB, it's what you want. )

You can try to bodge this through the user's file associations, but if my memory isn't playing tricks the obvious VB method of just shelling the name of the html file and letting the system sort out which application to use only works on the older (non NT base) Windows platforms (95/98/98SE).

Best solution I can think of is to use something like "ShellExec" (a little C++ program I use on auto running CD's to open an HTML file in the user's preferred browser). You could then possibly 'shell' from VB, calling ShellExec with the name of the html file and (if it works - I've not tried it but see no reason why it wouldn't) that would give you a robust method that would use the user's preferred browser to open the file AND work on all versions of Windows. :-)


Oh - legal copies of VB come with the reference MSDN CD's - which is probably describable as 'offline reference' material.

Al (MaDbRiT)

Anonymous
Ok as I'm feeling generous today, here's a VB example that works.

Open a new project, and navigate to the 'general declarations' area of form1 (form1 is created by default.)

Cut n paste all the code below into the form



Option Explicit

Private Declare Function ShellExecute Lib "shell32.dll" Alias _
"ShellExecuteA" (ByVal hwnd As Long, ByVal lpszOp As _
String, ByVal lpszFile As String, ByVal lpszParams As String, _
ByVal lpszDir As String, ByVal FsShowCmd As Long) As Long

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

Const SW_SHOWNORMAL = 1



Const SE_ERR_FNF = 2&
Const SE_ERR_PNF = 3&
Const SE_ERR_ACCESSDENIED = 5&
Const SE_ERR_OOM = 8&
Const SE_ERR_DLLNOTFOUND = 32&
Const SE_ERR_SHARE = 26&
Const SE_ERR_ASSOCINCOMPLETE = 27&
Const SE_ERR_DDETIMEOUT = 28&
Const SE_ERR_DDEFAIL = 29&
Const SE_ERR_DDEBUSY = 30&
Const SE_ERR_NOASSOC = 31&
Const ERROR_BAD_FORMAT = 11&

Function StartDoc(DocName As String) As Long
Dim Scr_hDC As Long
Scr_hDC = GetDesktopWindow()
StartDoc = ShellExecute(Scr_hDC, "Open", DocName, _
"", "C:\", SW_SHOWNORMAL)
End Function

Private Sub Form_Click()
Dim r As Long, msg As String

' Substitute the name of your file here.........

r = StartDoc("C:\ash_n_pauleen\index.html")
' ----------------------------------------------

If r <= 32 Then
'There was an error
Select Case r
Case SE_ERR_FNF
msg = "File not found"
Case SE_ERR_PNF
msg = "Path not found"
Case SE_ERR_ACCESSDENIED
msg = "Access denied"
Case SE_ERR_OOM
msg = "Out of memory"
Case SE_ERR_DLLNOTFOUND
msg = "DLL not found"
Case SE_ERR_SHARE
msg = "A sharing violation occurred"
Case SE_ERR_ASSOCINCOMPLETE
msg = "Incomplete or invalid file association"
Case SE_ERR_DDETIMEOUT
msg = "DDE Time out"
Case SE_ERR_DDEFAIL
msg = "DDE transaction failed"
Case SE_ERR_DDEBUSY
msg = "DDE busy"
Case SE_ERR_NOASSOC
msg = "No association for file extension"
Case ERROR_BAD_FORMAT
msg = "Invalid EXE file or error in EXE image"
Case Else
msg = "Unknown error"
End Select
MsgBox msg
End If
End Sub





Now, where I have marked in the above code, substitute the name including path of your HTML file name (or any other doc you want to open by association)

run the project and click the form.

Modify as required :-)

Al (MaDbRiT)

Alex
That code will also work if you put a web address like "http://www.axeuk.com/" in the call to the StartDoc function, which is very handy indeed.

codingmasters
Al you are a lifesaver

Thanks heaps!

Matthew G.

codingmasters
Al, just wondering if I could put the following code which goes into the declarations section into a module because i need this code on all but three or four forms of a fourty form application. It's the same code from above

[code]Option Explicit

Private Declare Function ShellExecute Lib "shell32.dll" Alias _
"ShellExecuteA" (ByVal hwnd As Long, ByVal lpszOp As _
String, ByVal lpszFile As String, ByVal lpszParams As String, _
ByVal lpszDir As String, ByVal FsShowCmd As Long) As Long

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

Const SW_SHOWNORMAL = 1



Const SE_ERR_FNF = 2&
Const SE_ERR_PNF = 3&
Const SE_ERR_ACCESSDENIED = 5&
Const SE_ERR_OOM = 8&
Const SE_ERR_DLLNOTFOUND = 32&
Const SE_ERR_SHARE = 26&
Const SE_ERR_ASSOCINCOMPLETE = 27&
Const SE_ERR_DDETIMEOUT = 28&
Const SE_ERR_DDEFAIL = 29&
Const SE_ERR_DDEBUSY = 30&
Const SE_ERR_NOASSOC = 31&
Const ERROR_BAD_FORMAT = 11&[/code]

Thanks, Matthew G.[/code]

paul_one
Learn about how modules work....

codingmasters
I do know how modules work CW

Matthew G.

GameBoy
why did you make 2 topics asking the same question? you're annoying me again now.... :x

I think Im Dead
I think Im Dead wrote:you're annoying me again now.

codingmasters
Ste I didn't write two posts asking the same question. I don't know how it happened

Matthew G.

paul_one
If you know how modules work then why are you asking a question which is easily solvable by a module?

Make the procedure a global - along with all the variables and stuff - then just call the procedure normally through the various forms...

Oh - and HAHAHAHA... Nice one ITID!

codingmasters
Hey listen

I didn't post two posts with the same question. I don't know how it happened alright, so back off

Matthew G.

GameBoy
2 TOPICS

http://www.axeuk.com/phpBB2/viewtopic.php?t=270

thats the other one

codingmasters
I did not post a 2nd topic Ste. It wasn't me, I didn't do it. Alright.

Matthew G.

Jakk
Erm... click the link Ste gave you. You did make it.


codingmasters
I did not do it Jakk, and that goes for all of you

I don't know it happened. It wasn't me, I didn't do it

Jakk you obvisouly don't know what went on about a month ago now.

Now please, for the love of god, I didn't do it and I don't know how it happened. So please stop annoying me, because I'm not trying to anny you

Matthew G.

007bond
Sorry for digging up an old post, but I had to comment on this one:
You guies obvisouly gave codingmasters a really hard time in this thread. Why didn't you just believe him and stop annoying him? That's possibly one of the reasons y he left.

paul_one
I don't care much :P .

GameBoy
007bond wrote:Sorry for digging up an old post, but I had to comment on this one:
You guies obvisouly gave codingmasters a really hard time in this thread. Why didn't you just believe him and stop annoying him? That's possibly one of the reasons y he left.


he didn't leave moron, he's you...

This topic is now closed. Topics are closed after 14 days of inactivity.

Support

Forums