描述:
'我用VB 做了一个类用来接收Excel的事件, 代码如下, 不知道用C + 如何实现, 谢谢了!
Private WithEvents AP As Excel.Application
Private WithEvents Wb As Excel.Workbook
Private Sub AP_WorkbookOpen(ByVal Wb As Excel.Workbook)
MsgBox Wb.Name
End Sub
Private Sub Wb_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Excel.Range)
MsgBox Sh.Name & "__" & Target.Address
End Sub
Public Sub setApp()
On Error Resume Next
Dim AP1 As Excel.Application, WB1 As Excel.Workbook
Set AP = Nothing: Set Wb = Nothing: Set AP1 = Nothing: Set WB1 = Nothing
Set AP1 = GetObject(, "Excel.Application")
If AP1 Is Nothing Then Set AP1 = CreateObject("Excel.Application")
If AP1 Is Nothing Then MsgBox "setApp false!": Exit Sub
AP1.Visible = True: Set WB1 = AP1.ActiveWorkbook
If WB1 Is Nothing Then Set WB1 = AP1.Workbooks.Add
If WB1 Is Nothing Then MsgBox "setApp false!": Exit Sub
Set AP = AP1: Set Wb = WB1: MsgBox "setApp ok!"
End Sub