Results 1 to 15 of 15

Thread: VB6 - Module to launch IE

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Mar 2005
    Location
    Chicago
    Posts
    136

    VB6 - Module to launch IE

    I see a lot of people ask how to launch Internet Explorer to a specific web page. Didn't find anything in the CodeBank so I thought I'd post the way I've been doing it. The module contains some additional stuff for Windows Registry access as well.

    Basic operation would be to type LaunchIE(strURL). LaunchIE is the function and strURL would be a string with a URL in it, pretty self explanatory. Anyways, this module will access the registry for IE's path, then shell Internet Explorer and navigate to the specified site. This particular way to launch IE also creates each IE as a separate process, which people may or may not find useful. If you are doing anything where you need separate instances for separate user sessions this is will work. There are about a million different ways to do this and this is just one.

    The second one below is basically the same thing as above except it uses ShellExecute. Only difference is that it uses the default browser which could be anything (FrontPage, Word, etc.) and it does not create separate instances of the browser.

    Questions, comments, concerns? Leave a message.
    Attached Files Attached Files
    Last edited by bat711; May 31st, 2005 at 04:18 PM.

  2. #2
    Frenzied Member thegreatone's Avatar
    Join Date
    Aug 2003
    Location
    Oslo, Norway. Mhz:4800 x12
    Posts
    1,333

    Re: VB6 - Module to launch IE

    The most simplistic way of doing this would be

    VB Code:
    1. Shell "C:\Program Files\Internet Explorer\IEXPLORE.EXE http://www.google.co.uk"

    But the obvious advantage of the module is that it will search for the path if it is not situated in the default directory for whatever reason.
    Zeegnahtuer?

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Mar 2005
    Location
    Chicago
    Posts
    136

    Re: VB6 - Module to launch IE

    True, I just tried to make it so nothing was hardcoded and keep it portable. It's also easy to use it as an object.

    It's just that what I've been using it for this wouldn't work since I'm logging into a secure site and if a user launches to the website twice I would have problems with cookies since the object only creates one process.
    CodeBank: Launch IE

  4. #4
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: VB6 - Module to launch IE

    Quote Originally Posted by thegreatone
    The most simplistic way of doing this would be

    VB Code:
    1. Shell "C:\Program Files\Internet Explorer\IEXPLORE.EXE http://www.google.co.uk"

    But the obvious advantage of the module is that it will search for the path if it is not situated in the default directory for whatever reason.
    I perfer using the ShellExecute API do to this, but that is only because I've had Shell do some funky things. If anyone is interested in how to use that API for opening a specific web page, you can do a search. I've posted that code numerous times.

  5. #5
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171

    Re: VB6 - Module to launch IE

    I also prefer the ShellExecute API since it opens the default browser and you don't force the user to use IE


    Has someone helped you? Then you can Rate their helpful post.

  6. #6
    Fanatic Member
    Join Date
    Mar 2005
    Posts
    537

    Re: VB6 - Module to launch IE

    The easiest way to launch IE is

    VB Code:
    1. dim IE as object
    2. set IE = CreateObject("internetexplorer.application")
    3. IE.visible = true
    4. IE.navigate "URL HERE"

    -Sir Loin

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Mar 2005
    Location
    Chicago
    Posts
    136

    Re: VB6 - Module to launch IE

    Sir Loin - Unfortunately launching IE as an object will not give some people the results they desire if the are using cookies or it's a secure site. Launching through Shell or ShellExecute will create a new Internet Explorer Process each time you launch it. With multiple threads running off of one IE process, cookies are shared, so if you need people to log in or identify themselves somehow it would create a bit of a security hole.

    I'll add another version that uses ShellExecute and default browser. -- ADDED
    Last edited by bat711; May 31st, 2005 at 04:16 PM.
    CodeBank: Launch IE

  8. #8
    New Member
    Join Date
    Jan 2008
    Posts
    3

    Re: VB6 - Module to launch IE

    Sir Loin,

    Any idea if I can tell IE.navigate to navigate to a specific URL that is written in a corresponding field? Say [tracking_url]?

    Quote Originally Posted by Sir Loin
    The easiest way to launch IE is

    VB Code:
    1. dim IE as object
    2. set IE = CreateObject("internetexplorer.application")
    3. IE.visible = true
    4. IE.navigate "URL HERE"

    -Sir Loin

  9. #9
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171

    Re: VB6 - Module to launch IE

    How do you mean field? A database field? A textbox field?

    Either way, you should be able to do this :

    vb Code:
    1. IE.navigate Text1.Text 'or the recordset field instead of the text1.text


    Has someone helped you? Then you can Rate their helpful post.

  10. #10
    New Member
    Join Date
    Jan 2008
    Posts
    3

    Re: VB6 - Module to launch IE

    Ah, therein lies the sag, I'm not that well versed in VB..all I know is that I have a record in my table with the full URL I want IE to navigate to...called 'tracking_url'..when I try to tell VB to open to the specified URL in tracking_url, it simply tries to open to http://tracking_url.. and a lovely error page obviously

  11. #11
    New Member
    Join Date
    Dec 2009
    Posts
    2

    Re: VB6 - Module to launch IE

    dim IE as object
    set IE = CreateObject("internetexplorer.application")
    IE.visible = true
    IE.navigate "URL HERE"
    the code is working but the only problem that i have here that everytime its open a new iexplorer ..

    is there a code where i can define a iexplorer name like we do in html so all the website open in a same window
    Regards
    Sohail

  12. #12
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171

    Re: VB6 - Module to launch IE

    Quote Originally Posted by sohaildotcom View Post
    dim IE as object
    set IE = CreateObject("internetexplorer.application")
    IE.visible = true
    IE.navigate "URL HERE"
    the code is working but the only problem that i have here that everytime its open a new iexplorer ..

    is there a code where i can define a iexplorer name like we do in html so all the website open in a same window
    Regards
    Sohail
    If you declare the variable globally (Dim IE As Object) and not locally in a function, then you should be able to access it again and run the IE.navigate with a different URL.


    Has someone helped you? Then you can Rate their helpful post.

  13. #13
    New Member
    Join Date
    Dec 2009
    Posts
    2

    Re: VB6 - Module to launch IE

    Quote Originally Posted by manavo11 View Post
    If you declare the variable globally (Dim IE As Object) and not locally in a function, then you should be able to access it again and run the IE.navigate with a different URL.
    I didn't get that... i m sorry

    what i want the code so that i can opne all urls in a same iexplorer windows.
    if you could write me the code that would be great....

  14. #14
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171

    Re: VB6 - Module to launch IE

    Something like this I guess (untested):

    vb Code:
    1. Dim IE As Object
    2.  
    3. Private Sub Form_Load()
    4.     Set IE = CreateObject("internetexplorer.application")
    5.     IE.visible = true
    6. End Sub
    7.  
    8. Private Sub Command1_Click()
    9.     IE.navigate Text1.Text
    10. End Sub


    Has someone helped you? Then you can Rate their helpful post.

  15. #15
    New Member
    Join Date
    Feb 2010
    Posts
    1

    Re: VB6 - Module to launch IE

    Hi.. thanks for the tips, here is the code i used in the end pretty basic but effective. Example here is a link from a Work order field( in this case just a cell with contents beginning WRQ.....) to the web page where the request is stored, reuses the internet page if available or launches new instance, although potential for looping via error routine, but havnt come accross situation yet


    Code:
    'Global Declares
     Dim ie As Object
    
    
    Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal  Target As Range)
     On Error GoTo err_out
    
    
     If Target.Text <> "" And UCase(Mid(Trim(Target.Text), 1, 3)) = "WRQ" Then
      SrvNbr = Mid(Trim(Target.Text), 4, 7)
      UrlCde = "URL" & SrvNbr
      ie.navigate UrlCde
     End If
    
     Exit Sub
    
     err_out:
      'Create the IE Window if not running
      Set ie = CreateObject("internetexplorer.application")
      ie.Visible = True
      Resume
    End Sub
    Last edited by taedeen; Feb 2nd, 2010 at 10:46 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width