Created
June 16, 2016 01:21
-
-
Save kei0425/f345aca2065d68b9f6ceccfb6de4e1fd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Public Class ThisAddIn | |
Private eventWorksheets As List(Of Excel.Worksheet) | |
Private Sub ThisAddIn_Startup() Handles Me.Startup | |
' ワークブックアクティブイベント登録 | |
AddHandler Globals.ThisAddIn.Application.WorkbookActivate, New Excel.AppEvents_WorkbookActivateEventHandler(AddressOf add_handlers_to_book) | |
End Sub | |
Private Sub add_handlers_to_book(workbook As Excel.Workbook) | |
Me.eventWorksheets = New List(Of Excel.Worksheet) | |
For Each worksheet As Excel.Worksheet In workbook.Worksheets | |
If worksheet.Name = "Sheet2" Or worksheet.Name = "Sheet3" Then | |
' シート名が Sheet2かSheet3の場合、イベント登録 | |
AddHandler worksheet.SelectionChange, New Excel.DocEvents_SelectionChangeEventHandler(AddressOf selection_change) | |
' イベントを設定したワークシートを保持 | |
Me.eventWorksheets.Add(worksheet) | |
End If | |
Next | |
End Sub | |
Private Sub selection_change(target As Excel.Range) | |
Dim worksheet As Excel.Worksheet = target.Worksheet | |
worksheet.Cells(1, 1).Value = target.Address | |
GC.Collect() | |
End Sub | |
End Class |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment