Consulting

Results 1 to 2 of 2

Thread: Close IE using Caption Name

  1. #1
    VBAX Newbie
    Joined
    Jun 2012
    Posts
    4
    Location

    Close IE using Caption Name

    Hi,

    How can i close IE using Caption Name using VBA.

    Like "Title - Windows Internet Explorer"


  2. #2
    VBAX Expert shrivallabha's Avatar
    Joined
    Jan 2010
    Location
    Mumbai
    Posts
    750
    Location
    Hi,

    Here's one way using Word.Applications' task object.
    [VBA]Public Sub CloseIEWindow()
    Dim winWord As Object
    Dim boolYes As Boolean
    Dim Task As Object

    'Check if already a word instance is running
    On Error Resume Next
    Set winWord = GetObject(, "Word.Application")
    On Error GoTo 0

    'If no then create one instance for running this code
    If winWord Is Nothing Then
    Set winWord = CreateObject("Word.Application")
    winWord.Visible = False
    boolYes = True
    End If

    'Loop through tasks and then close the one which has desired caption
    For Each Task In winWord.Tasks
    If InStr(Task.Name, "Windows Internet Explorer") > 0 Then
    Task.Close
    End If
    Next Task

    'If it was word instance which we created then close it.
    If boolYes Then winWord.Quit

    End Sub
    [/VBA]

    If you do not want to use word route then there are some api's which can be used like in this thread:
    http://www.vbaexpress.com/forum/showthread.php?t=43576
    Regards,
    --------------------------------------------------------------------------------------------------------
    Shrivallabha
    --------------------------------------------------------------------------------------------------------
    Using Excel 2016 in Home / 2010 in Office
    --------------------------------------------------------------------------------------------------------

Posting Permissions

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