This message was edited by Moderator at 2003-11-4 20:17:9
: : :
Private WithEvents myExcel As Excel.Application
: : :
: : : Private Sub Form_Load()
: : : Set myExcel = New Excel.Application
: : : myExcel.Workbooks.Add
: : : myExcel.Visible = True
: : : End Sub
: : :
: : : Private Sub myExcel_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Excel.Range)
: : : MsgBox "New value is " & Target.Value & " and position is " & Target.Row & " " & Target.Column
: : : End Sub
When you declare varivable like WithEvent, in desing window (up, left) appears new object (beside Form1, Command1, Image1...) and it has all these events...
: : : Good luck
: : :
: : : PavlinII
: : :
: : :
: : Pavlin, thanks for your reply, but this line of your code:
: :
Private WithEvents myExcel As Excel.Application
: : gives me this compile error:
: :
User-defined type not defined
: :
: : Further, I do not understand how any of your code will tell me when Paste Event has occurred. Am I missing something?
: :
: There could be one reason of this: You didn't add reference to MS Excel library to you app, did you? Click:
Project/References/"Microsoft Excel x.0 Object Library", OK... (x.0 is version depending on your version of Excel - 5.0, 8.0, 9.0.. any) And now it could work... But I supposed that you have done this before you started to care about controling Excel

...
:
: PavlinII
:
Sorry, I forgot to answer the second part...
When you define WithEvents iExcel blablabla, you get object iExcel. This iExcel equals to Excel (but it's just not displayed yet) - you can do everything that excel can do...
When you open VB editor in Excel (Alt+F11) and doubleclick on sheet name (list1) in Project Explorer you gets place, where you can write code attached to this list (or any other one.. it behaves nearly like module) and there exist one predefined object
Worksheet.. and when you choose this object, you'll get list of all events that WorkSheet has (Like form: Activate, Load, Click, Unload etc.) but here are useful things like BeforeDoubleClick, AfterDoubleClick, Calculate,
SelectionChange.. And SelectionChange is important for you, because this event is generated (called) everytime when any cell is changed (there is typed or pasted text for example).. And if you take your code that controls if the pasted text (or value, I don't know) is correct, it will control what you want everytime after some cell changed.. Do you understand? You can play with this there... And if you define iExcel like WithEvents, you gets all these nice events too... So you will know when any cell is changed...
In that code it was sub myExcel_SheetSelectionChange... It even gives you Targed - the changed cell!
Hope it's clear now. If you still don't understand any part of this, ask..
PavlinII