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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to pop up actual internet explorer/ms word

Status
Not open for further replies.

nim180

IS-IT--Management
Aug 11, 2005
161
AU
I was wondering if the following is possible:

1. I have a form with 2 buttons, when the user clicks on the 1st button i would like an instance of internet explore to pop up, i know you can create your own instance of internet explore in a form but is it possible to get the actual explorer to pop up. The 2nd button would open ms word (the acutal program and not a specific document).

2.I have a small form with a countdown timer on it. When the form is opened it pops up and appears in the bottom right hand corner of the screen. Now assuming part one is possible...is there a way that the timer form can always stay poped up when an instance of internet explorer or word is running, this is so whoever is using explorer or word can see how much time they have left.

Thanks,
Nim
 
Here are some notes.

It is easy enough to open a blank application, however, this may lead to problems determining if a particular instance is the one you opened You may wish to get the window handle to check. I will look into this a little more.


Code:
Sub OpenApps()
Dim ws As Object
Dim IE As Object
Set ws = CreateObject("Word.Application")
ws.Visible = True
Set IE = CreateObject("InternetExplorer.Application")
IE.Navigate "about:blank"
IE.Visible = True
End Sub

Determine is an instance of Word or IE is running. This does not check if the instance is the one you opened.

Code:
Function WSRunning() As Boolean
'This will not work for IE
Dim ws As Object

On Error Resume Next
Set ws = GetObject(, "Word.Application")

If Err.Number = 0 Then
    WSRunning = True
Else
    Err.Clear
End If

End Function

Function IERunning() As Boolean
'From: [URL unfurl="true"]http://www.vbforums.com/showpost.php?p=1634238&postcount=4[/URL]
Dim objInstances As Object, objIE As Object
 
Set objInstances = CreateObject("Shell.Application").Windows
 
If objInstances.Count > 0 Then '/// make sure we have instances open.
 
    For Each objIE In objInstances
    Dim sName As String
    sName = objIE.FullName
    
    If Right(sName, 12) = "IEXPLORE.EXE" Then '/// it's internet explorer not windows explorer.
        IERunning = True
    End If
 
    Next
End If
 
End Function

It is also possible to check if an instance exists using APIs, with the same problem of deciding if this is the instance you started or not.

Code:
Option Compare Database
Option Explicit

Private Const GW_HWNDNEXT = 2
Private Declare Function GetWindow Lib "user32" (ByVal hwnd As Long, ByVal wCmd As Long) As Long
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long


Function FindWindowPartial(ByVal Title As String) As String
    Dim hWndThis As Long

    hWndThis = FindWindow(vbNullString, vbNullString)
    While hWndThis
        Dim sTitle As String, sClass As String
        sTitle = Space$(255)
        sTitle = Left$(sTitle, GetWindowText(hWndThis, sTitle, Len(sTitle)))
        If InStr(sTitle, Title) > 0 Then
            FindWindowPartial = sTitle & "|" & FindWindowPartial
        End If
        hWndThis = GetWindow(hWndThis, GW_HWNDNEXT)
    Wend
End Function

Function WSRunningAPIVer() As Boolean
WSRunningAPIVer = (FindWindowPartial("Microsoft Word") > vbNullString)
End Function

Function IERunningAPIVer() As Boolean
IERunningAPIVer = (FindWindowPartial("Windows Internet Explorer") > vbNullString)
End Function

 
Hi Remou,

That worked fine but both applications when opened, opens in the background, how do i get them to pop up infront of the forms?

Also is it possible to achieve part 2 of my question.

Thanks,
nim
 
There are several ways of opening an application:


Code:
Sub OpenWithShell()
    IE = Shell("C:\Program Files\Internet Explorer\IExplore.exe", vbNormalNoFocus)

    ws = Shell("C:\Program Files\Microsoft Office\OFFICE\WinWord.exe", vbNormalNoFocus)
End Sub[code]

However, with the above, you will need a directory, and internet explorer will open to the home page.

With my original suggestion:

[CODE]Sub OpenApps()
Dim ws As Object
Dim IE As Object
Set ws = CreateObject("Word.Application")
ws.Visible = True
[b]ws.Activate
'Or GetObject at any stage when Word is open
'Set ws=GetObject(,"Word.Application")[/b]
Set IE = CreateObject("InternetExplorer.Application")
IE.Navigate "about:blank"
IE.Visible = True
End Sub

Unfortunately, Activate and GetObject do not work with Explorer, with explorer it is easier if there is a suitable URL.

As for part 2, that is the point of the additional code that allows you to check if word or explorer are running. The idea is that you check in your existing timer and if an instance is not running, close the pop-up, otherwise leave it. If you get stuck, please post back the code.

You may find that the timer and pop-up prevent the application you run from getting focus.



 
Thanks Remou for your help but im a bit confused. Ill try and explain it a bit better :) The user starts with a login form....when the user logs in with a username/password it automatically opens the timer form in the bottom right hand corner of the screen and it also opens the main database form.

The main database form has varies different buttons. When the user clicks on the IE button, the IE application opens but hides the access program. What i would like is for the timer form to always be in the bottom right hand corner of the screen and visible nomatter if IE or MsWord are being used, but when IE or MsWord are run the form is hidden even though it is still running and counting down. I would like this timer form to be visible at all times.

Hope that explains a bit more.

Thanks
Nim
 
Thanks Remou, any help will do :)
 
Hey Remou, any more suggestions about my query above or maybe someone else might have some idea.

Thanks,
Nim
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top