|
-
Feb 5th, 2003, 04:03 AM
#1
Thread Starter
New Member
How to determine if excel application is running on Internet Explorer using VB code
Hi all !!
Can anyone help me out !!!
How to determine if the excel application is opened (or running) through Internet Explorer. Actually have created excel add-ins using VBA, have written a function on On_Connection event which fires when excel instance is invoked (i.e, when excel application is opened), now, the function in the On_connection event should not fire if a excel file is opened through IE.
The function in On_Connection event is fired only if the excel file is directly opened through Excel Application.
How do we determine if the excel application is invoked through IE ? Need VB code to determine this ??
Expecting some solution
Thanks in advance.
-
Feb 8th, 2003, 12:18 AM
#2
Fanatic Member
this is what microsoft says. (it brings you back the full task list, but your exel should be somewhere in there.) it's as early as vb3, so i think you have to change
Declare Function ... Lib "user"
with
Declare Function ... Lib "user32"
(at least). good luck!!
------------------------
Here are the steps necessary to construct a sample program that demonstrates how to load the task list into a Visual Basic combo box:
Start Visual Basic or choose New Project from the File menu (ALT+F, N) if Visual Basic is already running. Form1 is created by default.
Change the caption property of Form1 to AppActivate.
Add the following controls to Form1, and change the Name property as indicated:
Control Default Name Name
---------------------------------------------------------
Label Control Label1 Label1
Combo Box Combo1 Combo_ListItem
Command Button Command1 Command_Ok
Change the Caption properties of the controls as follows:
Control Name Caption
-----------------------------------------------------------
Label Control Label1 Application to AppActivate:
Command Button Command_OK OK
Add the following code to the general declarations section of Form1:
DefInt A-Z
'Windows API function declarations:
'Enter each entire Declare statement on one, single line:
Declare Function GetWindow Lib "user" (ByVal hWnd%, ByVal wCmd%)
As Integer
Declare Function GetWindowText Lib "user" (ByVal hWnd%, ByVal lpSting$,
ByVal nMaxCount%) As Integer
Declare Function GetWindowTextLength Lib "user" (ByVal hWnd%) As Integer
'Declare constants used by GetWindow.
Const GW_CHILD = 5
Const GW_HWNDFIRST = 0
Const GW_HWNDLAST = 1
Const GW_HWNDNEXT = 2
Const GW_HWNDPREV = 3
Const GW_OWNER = 4
Add the following code to the Form_Load event procedure of Form1:
Sub Form_Load ()
Call LoadTaskList
'If no items are in the task list, end the program.
If Combo_ListItem.ListCount > 0 Then
Combo_ListItem.Text = Combo_ListItem.List(0)
Else
MsgBox "Nothing found in task list", 16, "AppActivate"
Unload Form1
End If
End Sub
Add the following code to the Click event procedure of the Command_Ok button:
Sub Command_Ok_Click ()
'Get the item selected from the text portion of the combo box.
f$ = Combo_ListItem.Text
'Resume if "Illegal function call" occurs on AppActivate statement.
On Local Error Resume Next
AppActivate f$
End Sub
Add the following code to the general declarations section of Form1:
Sub LoadTaskList ()
'Get the hWnd of the first item in the master list
'so we can process the task list entries (top-level only).
CurrWnd = GetWindow(Form1.hWnd, GW_HWNDFIRST)
'Loop while the hWnd returned by GetWindow is valid.
While CurrWnd <> 0
'Get the length of task name identified by CurrWnd in the list.
Length = GetWindowTextLength(CurrWnd)
'Get task name of the task in the master list.
ListItem$ = Space$(Length + 1)
Length = GetWindowText(CurrWnd, ListItem$, Length + 1)
'If there is a task name in the list, add the item to the list.
If Length > 0 Then
Combo_ListItem.AddItem ListItem$
End If
'Get the next task list item in the master list.
CurrWnd = GetWindow(CurrWnd, GW_HWNDNEXT)
'Process Windows events.
x = DoEvents()
Wend
End Sub
From the Run menu, choose Start (ALT+R, S) to run the program.
From the combo box, select the window title of an application currently running in Windows. Choose the OK button to activate the application.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|