If statement for calling modules


I have code that populates a listbox if there is more than one IE window that has "View" in the title. I am trying to expand on that code to make an if...then statement that will do these things:

If > 1 IE window with "View" in the title, populate listbox

If only one  IE window with "View" in the title, continue to Call fEnumWindows

If there are not any IE windows with "View" in the title, pop a msgbox indicating such.

The code below seems to perform all three actions and not correctly jump to the appropriate if...then.

Any help is appreciated.

Dim IE As New InternetExplorer
    Dim SH As New ShellWindows
    For Each IE In SH
        If InStr(1, IE.Document.Title, "View", vbTextCompare) > 1 Then
            MsgBox "Opening listbox"
        ElseIf InStr(1, IE.Document.Title, "View", vbTextCompare) = Null Then MsgBox "There are tickets displayed on the screen."
            MsgBox "Will now update the only open ticket"
            Call fEnumWindows
        End If
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

You could keep count of the windows...

Dim count As Long

For Each IE In SH
    If InStr(1, IE.Document.Title, "View") Then
        'populate listbox
        'MsgBox "Opening listbox"
        List1.AddItem IE.LocationName
        count = count + 1
    End If

If count = 0 Then
    MsgBox "No windows with " & Chr(34) & "View" & Chr(34) & " in Title"
End If

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
jkrech17Author Commented:

Thanks for the help. I used the If count along with else if to get the results I needed.

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.