返回列表 上一主題 發帖

[發問] 有兩個獨立EXCEL,如何知道切換到另一個獨立EXCEL?

本帖最後由 GBKEE 於 2015-7-27 14:03 編輯

回復 16# justintoolbox



Module1的程式碼
  1. Option Explicit
  2. Public xApp As New Class1
  3. Dim NewApp As New Application
  4. Sub Ex()
  5.     Set xApp.The_App = NewApp
  6. End Sub
複製代碼
物件類別模組 Class1 的程式碼
  1. Option Explicit
  2. Dim WithEvents APP As Application
  3. Property Set The_App(P As Object)
  4.     Set APP = P    ' 將 APP 屬性值設成物件。
  5.     With APP
  6.         .Visible = True
  7.         With .Workbooks.Add
  8.             .Sheets(1).[a1] = 5
  9.         End With
  10.     End With
  11. End Property

  12. Private Sub APP_NewWorkbook(ByVal Wb As Workbook)
  13.     MsgBox Wb.Name
  14. End Sub
  15. Private Sub APP_SheetChange(ByVal Sh As Object, ByVal Target As Range)
  16.     MsgBox Target.Address(, , , 1, 1)
  17. End Sub
複製代碼
感恩的心......(在麻辣家族討論區.用心學習會有進步的)
但資源無限,後援有限,  一天1元的贊助,人人有能力.

TOP

本帖最後由 GBKEE 於 2015-7-28 11:07 編輯

回復 18# justintoolbox
我希望能藉由觸發程序告訴我有切換到另一個獨立EXCEL.
VBA Application 物件的事件找不到支援的事件.
這就是兩個獨立EXCEL.物件類別的Application事件.可得知另一個獨立EXCEL的活動.
  1. Option Explicit
  2. Dim WithEvents APP As Application
  3. Property Set The_App(P As Object)
  4.     Set APP = P    ' 將 APP 屬性值設成物件。
  5.     With APP
  6.         .Visible = True
  7.     End With
  8. End Property

  9. Private Sub APP_NewWorkbook(ByVal Wb As Workbook)
  10.     MsgBox Wb.Name
  11. End Sub
  12. Private Sub APP_SheetChange(ByVal Sh As Object, ByVal Target As Range)
  13.     MsgBox Target.Address(, , , 1, 1)
  14. End Sub

  15. Private Sub APP_WindowActivate(ByVal Wb As Workbook, ByVal Wn As Window)
  16.    
  17.     MsgBox "進入 " & Wb.Name
  18. End Sub

  19. Private Sub APP_WindowDeactivate(ByVal Wb As Workbook, ByVal Wn As Window)
  20.     MsgBox "退出 " & Wb.Name
  21. End Sub

  22. Private Sub APP_WindowResize(ByVal Wb As Workbook, ByVal Wn As Window)
  23.     MsgBox Wn.Caption & "變化視窗"
  24. End Sub
複製代碼
感恩的心......(在麻辣家族討論區.用心學習會有進步的)
但資源無限,後援有限,  一天1元的贊助,人人有能力.

TOP

        靜思自在 : 對父母要知恩,感恩、報恩。
返回列表 上一主題