Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Capture Excel Events from other application

Who know how to capture excel event for example 'Workbook_BeforeClose'
from other application for example MSWord. Using WithEvents in MSWord
class doesn't work, so I guess it impossible to do that.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10
Default Capture Excel Events from other application

George wrote:
Who know how to capture excel event for example 'Workbook_BeforeClose'
from other application for example MSWord. Using WithEvents in MSWord
class doesn't work, so I guess it impossible to do that.


Setting a reference (early binding) to Excel and then declaring:

Private WithEvents m_objExcel As Excel.Application

Gives me access to:

Private Sub m_objExcel_WorkbookBeforeClose(ByVal Wb _
As Excel.Workbook, Cancel As Boolean)

End Sub

So it does work, and is possible.

HTH

--
Rob

http://www.asta51.dsl.pipex.com/webcam/


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 860
Default Capture Excel Events from other application

Hi George,

As Rob said, this is definitely possible.

Create a class module named "CXLWBSink" and add the following code to it:

Public WithEvents xlWB As Excel.Workbook

Private Sub xlWB_SheetChange(ByVal Sh As Object, _
ByVal Target As Excel.Range)
Target.Cells.Interior.ColorIndex = 3
End Sub

Now, create a standard module and add the following code to it:

Dim CxlwbSink As CxlwbSink

Sub StartDemo()
Dim xlApp As Excel.Application

Set CxlwbSink = New CxlwbSink

Set xlApp = New Excel.Application

Set CxlwbSink.xlWB = xlApp.Workbooks.Open("C:\test.xls")
xlApp.UserControl = True
xlApp.Visible = True

Set xlApp = Nothing
End Sub

Sub EndDemo()
Dim xlApp As Excel.Application

On Error Resume Next
If Not CxlwbSink.xlWB Is Nothing Then
Set xlApp = CxlwbSink.xlWB.Application
CxlwbSink.xlWB.Close False
xlApp.Quit
Set xlApp = Nothing
End If
Set CxlwbSink = Nothing
End Sub


Now, if you run StartDemo, you should get a new Excel app with test.xls open
(assuming that's a valid file path). If you change any cell in that
workbook, the cell fill color should change. When you're done, run EndDemo
to kill the instance of Excel.

This is totally off the cuff, so I'm sure you'll need to add some error
handling and tighten the code up, but I just wanted to show you that it does
work.

--
Regards,

Jake Marx
MS MVP - Excel
www.longhead.com

[please keep replies in the newsgroup - email address unmonitored]


George wrote:
Who know how to capture excel event for example 'Workbook_BeforeClose'
from other application for example MSWord. Using WithEvents in MSWord
class doesn't work, so I guess it impossible to do that.


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Capture Excel Events from other application



Thanks a lot for your reply. It is really help. But I wonder if it work
using late binding for example Getobject(,Excel.Application).

Thanks again

George

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Capture Excel Events from other application



Great example. Amazing!different application can work together in this
way

Thank you

George

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!


  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10
Default Capture Excel Events from other application

George Eskildsen wrote:
Thanks a lot for your reply. It is really help. But I wonder if it
work using late binding for example Getobject(,Excel.Application).


Well, the withevents declaration doesn't work with late binding. However,
GetObject is NOT late binding. If you assign the return value of GetObject
to an early-bound variable, then withevents will work.

Rob


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Using Events with the Application Object & XL 2003 Kevin H. Stecyk[_2_] Excel Programming 13 January 25th 05 04:40 PM
Application Events / App_WorkbookOpen Fries[_2_] Excel Programming 5 December 18th 04 01:21 PM
Using Application Events Thomas Herr Excel Programming 2 April 5th 04 09:24 PM
How-To - Forwarding Excel 2000 events to .Net application Joel Foner Excel Programming 0 January 28th 04 11:34 PM
capture users Application.OnKey RB Smissaert Excel Programming 1 September 8th 03 02:49 PM


All times are GMT +1. The time now is 01:08 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"