Opening a specific page in IE through VB
codingmasters
30 Dec 2003, 04:32And just for you Ste, I've already tried this question on vbforums.com and no-one answered my post
Matthew G.
Anonymous
30 Dec 2003, 10:34How 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
30 Dec 2003, 11:20Open 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
30 Dec 2003, 13:33codingmasters
31 Dec 2003, 19:52Thanks heaps!
Matthew G.
codingmasters
31 Dec 2003, 20:47[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
01 Jan 2004, 07:44codingmasters
01 Jan 2004, 09:43Matthew G.
GameBoy
01 Jan 2004, 17:53I think Im Dead
01 Jan 2004, 21:54I think Im Dead wrote:you're annoying me again now.
codingmasters
01 Jan 2004, 22:42Matthew G.
paul_one
02 Jan 2004, 08:15Make 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
02 Jan 2004, 21:13I didn't post two posts with the same question. I don't know how it happened alright, so back off
Matthew G.
GameBoy
03 Jan 2004, 00:04codingmasters
03 Jan 2004, 20:43Matthew G.
Jakk
03 Jan 2004, 21:03paul_one
03 Jan 2004, 21:29codingmasters
04 Jan 2004, 06:59I 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
22 Sept 2004, 09:20You 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
29 Sept 2004, 06:46GameBoy
29 Sept 2004, 07:15007bond 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...