Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Is application (IE) running? 2

Status
Not open for further replies.

smitan

Programmer
May 11, 2002
115
DK
In a form with company info I open Internet Explorer for the user. This may result in multiople sessions of IE. I could hae a flag to control this, but when the user closes IE, the flag is still raised and IE is closed.

There must be a way (via API) to check if an aplication is running or not.

Next to that, is there a way to enter a value in a field ( in IE? In geberal, is it possible to 'control' the other appliaction, except from using Sendkeys?

Have fun with VBA.
Hans
 
While not directly answering your problem, which is certainly possible but quite involved, the code in my FAQ222-2066 may do the job you want i.e. use an existing browser if already open, or open a new one if not.
 
Yhank you Norris68, it certainly is more flexible then the method I use (Shell "C:\Program Files\Internet Explorer\IEXPLORE.EXE " & WebSite, vbNormalFocus).
It also opens in the same browser, so not to create x instants.

Nevertheless I am interested in other possibilities as there is a little extra thing. When clicking on a company name I raise the question "Do you want me to open xxx for you?".
The website that is opened on a 'yes' has an initialize and logon. So what I am trying to accomplish is to avoind the question and the initialize when the IE is opened already.

Thanks again.
Hans
 
This isn't as simple as it might seem.

In a module paste the following:

Declare Function EnumWindows Lib "user32.dll" (ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long
Declare Function GetWindowTextLength Lib "user32.dll" Alias "GetWindowTextLengthA" (ByVal hWnd As Long) As Long
Declare Function GetWindowText Lib "user32.dll" Alias "GetWindowTextA" (ByVal hWnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Declare Function GetActiveWindow Lib "user32.dll" () As Long

Global ghWnd As Long
Global gCurrenthWnd As Long
Global IsIEOpen As Boolean

Public Function EnumWindowsProc(ByVal hWnd As Long, ByVal lParam As Long) As Long
On Error Resume Next
Dim slength As Long, TitleBar As String
Dim retval As Long
Static winnum As Integer
IsIEOpen = False
winnum = winnum + 1
slength = GetWindowTextLength(hWnd) + 1
If slength > 1 Then
TitleBar = Space(slength)
retval = GetWindowText(hWnd, TitleBar, slength)
If InStr(TitleBar, "- Microsoft Internet Explorer") Then
IsIEOpen = True
Exit Function
End If
End If
EnumWindowsProc = 1
End Function

To test the function, in the on click event of a form paste:

Call EnumWindows(AddressOf EnumWindowsProc, 0)
MsgBox IsIEOpen

Bill

 
Thank you very much BillPower.
Copy/Paste is very simple, the way it functions maybe less :-{

As this specific website is a search web for extended company info, it might be nice to the user, to set the focus to the IE and to supply the search argument into the proper field.

I hope you also have a solution for this?

I am highly impressed by your knowledge and find it amazing that you always have a good answer to the question.
Add a star to all those you already have.

Hans
 
Hi smitan,

Thanks for your kind comments. I really would like to help you further, but can you explain a bit more, maybe give me some examples.

1. Existing code in Access and expected code etc.

2. Web Sites in IE

3. And anything else you can think of.

Thanks for the star too, much appreciated. You go on my quick response list AON.

Bill
 
You are most welcome.

The form is a continues one, showing the CompanyName.
Clicking on the CN checks the value of a field, if 0 asks for IE to be opened and opens a CmpDetail form.

What I would like is: Clicking on the CN will still open the detail form, but as for the question and IE, only have them when IE is not yet opened with the proper website. Therefore the check on Title Bar is changed to the website name.

Thankx
Hans
 
As more or less explained, the idea is a click on CompanyName, followed by the question ‘Do you want me to open the Website for you?’

If yes, open website, user clicks OK (the secret codes are filled in).

Next time a user clicks a CompanyName, which does not have an ID that links to the info in this WebDatabase, the question is not asked anymore, the proper codes are being sendt, so as to come on the right tab.

After that, the company name is ‘send’ to the website end the focus is set to the website.

I hope this will give you the idea.

Thanks a forehand.

Hans
 
Hi Hans,

Just to let you know that I am still working on this. My first thoughts were that this would do the trick, with an added "Find". Unfortuneately it only works first time.

For some reason the pop-up where the username etc is entered doesn't receive the focus after a second attempt.

Try it for yourself, let me know if you have the same problem.

Over the weekend will look into trying this with an API or two:

Dim strCompany As String
strCompany = "Nordicom"
Application.FollowHyperlink " True
SendKeys "{Tab}{Tab}{Tab}{Tab}{Enter}", True
SendKeys strCompany

Bill
 
Here are my thoughts:

The user may be looking at his email via the web, researching, etc., so leave the existing browser alone.

Create a new instance of the IE Object like this:

In a module:
Code:
Dim objie As Object
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

Function OpenBrowser(ByVal sURL As String)
    Set objie = CreateObject("InternetExplorer.Application")

    '=======================================
    ' Navigate to a web page and display it when it is
    ' finished loading
    '=======================================
    objie.Navigate (sURL)

    While objie.busy = True
          Sleep 500
    Wend

    objie.Visible = True

    Set objie = Nothing

End Function
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top