タイトル | : エクセルのイベントをを処理する方法 |
記事No | : 10128 |
投稿日 | : 2010/06/05(Sat) 00:59 |
投稿者 | : keisuke |
いつもお世話になっています。
・環境 OS : Windows7(32bit) Visual basic 2008 Express Edition EXCEL2003で開発しています、、、 エクセルのイベントをを処理する方法なのですが。 http://support.microsoft.com/kb/822750/ja を参考にしてトライしているのですが、セルを右クリックのイベントが 取れません http://support.microsoft.com/kb/213220/ja あたりも参考にしていますが、迷路に陥っています。 下のようなコードですが、CellsChangeとBeforeBookCloseのイベントは動作しますが BeforeRightclickは動作しません(メソッド 'Private Sub BeforeRightclick(Target As Microsoft.Office.Interop.Excel.Range)' に、デリゲート 'Delegate Sub DocEvents_BeforeRightClickEventHandler(Target As Microsoft.Office.Interop.Excel.Range, ByRef Cancel As Boolean)' と互換性があるシグネチャがありません。)とエラーは出ています、HELPを探してもBeforeRightclickの処が あまり参考になりませんです、BeforeRightclickイベントを拾うにはどうしたら、良いのでしょうか??記述の仕方が悪いのか、、躓いています BeforeRightclickイベントの取り方をおしえてください。 よろしくお願いします。
’***************** Imports Microsoft.Office.Interop
Module Module1 '================================================================== 'Demonstrates Using a Delegate for Event Handling '==================================================================
Private xlApp As Microsoft.Office.Interop.Excel.Application Private xlBook As Microsoft.Office.Interop.Excel.Workbook Private xlSheet1 As Microsoft.Office.Interop.Excel.Worksheet Private xlSheet2 As Microsoft.Office.Interop.Excel.Worksheet Private xlSheet3 As Microsoft.Office.Interop.Excel.Worksheet Private EventDel_BeforeBookClose As Microsoft.Office.Interop.Excel. _ AppEvents_WorkbookBeforeCloseEventHandler Private EventDel_CellsChange As Microsoft.Office.Interop.Excel. _ DocEvents_ChangeEventHandler Private EventDel_BeforeRightClick As Microsoft.Office.Interop.Excel. _ DocEvents_BeforeRightClickEventHandler Dim instance As Microsoft.Office.Interop.Excel.Worksheet Dim handleras As Microsoft.Office.Interop.Excel.DocEvents_BeforeRightClickEventHandler
Public Sub UseDelegate()
'Start Excel and then create a new workbook. xlApp = CreateObject("Excel.Application") xlBook = xlApp.Workbooks.Add() xlBook.Windows(1).Caption = "Uses WithEvents"
'Get references to the three worksheets. xlSheet1 = xlBook.Worksheets.Item(1) xlSheet2 = xlBook.Worksheets.Item(2) xlSheet3 = xlBook.Worksheets.Item(3) CType(xlSheet1, Microsoft.Office.Interop.Excel._Worksheet).Activate()
EventDel_BeforeBookClose = New Microsoft.Office.Interop.Excel. _ AppEvents_WorkbookBeforeCloseEventHandler(AddressOf BeforeBookClose) AddHandler xlApp.WorkbookBeforeClose, EventDel_BeforeBookClose
EventDel_CellsChange = New Microsoft.Office.Interop.Excel. _ DocEvents_ChangeEventHandler(AddressOf CellsChange) AddHandler xlSheet1.Change, EventDel_CellsChange AddHandler xlSheet2.Change, EventDel_CellsChange AddHandler xlSheet3.Change, EventDel_CellsChange 'この部分でエラーになっています EventDel_BeforeRightClick = New Microsoft.Office.Interop.Excel. _ DocEvents_BeforeRightClickEventHandler(AddressOf BeforeRightclick)
AddHandler xlSheet1.BeforeRightClick, EventDel_BeforeRightClick
xlApp.Visible = True xlApp.UserControl = True
End Sub
Private Sub CellsChange(ByVal Target As Microsoft.Office.Interop.Excel.Range) Debug.WriteLine("Delegate: You Changed Cells " + Target.Address + " on " + _ Target.Worksheet.Name()) End Sub
Private Sub BeforeRightclick(ByVal Target As Microsoft.Office.Interop.Excel.Range) Debug.WriteLine("Delegate: You BeforeRightClick " + Target.Address + " on " + _ Target.Worksheet.Name()) End Sub
Private Sub BeforeBookClose(ByVal Wb As Microsoft.Office.Interop.Excel.Workbook, _ ByRef Cancel As Boolean)
Debug.WriteLine("Delegate: Closing the workbook and removing event handlers.") RemoveHandler xlSheet1.BeforeRightClick, EventDel_BeforeRightClick RemoveHandler xlSheet1.Change, EventDel_CellsChange RemoveHandler xlSheet2.Change, EventDel_CellsChange RemoveHandler xlSheet3.Change, EventDel_CellsChange RemoveHandler xlApp.WorkbookBeforeClose, EventDel_BeforeBookClose Wb.Saved = True 'Set the dirty flag to true so there is no prompt to save. End Sub End Module
|