PDA

View Full Version : Close IE using Caption Name



ssingh75
07-02-2013, 01:51 AM
Hi,

How can i close IE using Caption Name using VBA.

Like "Title - Windows Internet Explorer"

:doh:

shrivallabha
07-02-2013, 10:08 AM
Hi,

Here's one way using Word.Applications' task object.
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


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