Results 1 to 2 of 2

Thread: Close Browser Tab with VB

Hybrid View

  1. #1
    New Member
    Join Date
    Apr 12
    Posts
    3

    Close Browser Tab with VB

    Is there a way to close an IE browser tab with VB? I've searched for hours and feel I'm missing something simple.

    Here's the basic idea:

    I'm importing data into Excel from web pages that also have links to pages that contain additional (detail) data. I open IE and navigate to a page, find the link, open a second tab... but after I access that second tab, I need to close it.

    Here's some of the code I'm using -- everything works as expected until I need to close the second tab:

    Code:
    Sub MainProcess()
    ' Note that I have enabled references to the Microsoft HTML Object Library and Microsoft Internet Controls
        Dim IE As SHDocVw.InternetExplorer
        IE.Navigate URL
        ' some code to get the first batch of data I need and find the links to the additional data
        wbOpenNewTab detailLink ' where detailLink is defined above
    End Sub
    
    Private Sub wbOpenNewTab(URL)
        IE.Navigate2 URL, 1
        ' This is where I copy the data I need
        IE.Quit ' This incorrectly closes the first tab, not the one I just opened
    End Sub
    Any help is appreciated.

  2. #2
    PowerPoster
    Join Date
    Dec 04
    Posts
    18,587

    Re: Close Browser Tab with VB

    it would be possible to loop through the shell windows, to find the appropriate one, based on some criteria (eg. the url), and close it
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

Posting Permissions

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