- 帖子
- 57
- 主題
- 14
- 精華
- 0
- 積分
- 73
- 點名
- 0
- 作業系統
- win8.1
- 軟體版本
- office2010
- 閱讀權限
- 20
- 註冊時間
- 2015-4-2
- 最後登錄
- 2019-6-17
|
回復 justintoolbox
不好意思,剛剛我貼的行不通
我照你的方法開啟excel,真的不行
no3-taco 發表於 2015-7-25 12:17 
no3-taco前輩,謝謝你的幫忙。
我有查到網路上的類似的問題。我把代碼放在底下(上一封的代碼是我依照下面的代碼修正而來,可顯示多少個獨立EXCEL)。
測試結果:
我在a.xlsm執行過底下代碼的test程序,結果debug.print出來是一串長整數。
如果這時候:『按下shit鍵並在a.xlsm按下左鍵』,則會新增出一個獨立的excel檔。
這時候在a.xlsm執行test程序,會出現兩串長整數。
感想:
只知道這兩串各代表著兩個獨立EXCEL,但卻不知道如何利用?
我有思考:若知道這兩串數字,就說不定可以操控個別獨立EXCEL了(也就可以知道另一個獨立EXCEL檔名了)
懇請各位前輩或高手們,出手相救∼ 感謝!∼- Option Explicit
- Private Declare PtrSafe Function FindWindowEx Lib "user32" Alias _
- "FindWindowExA" ( _
- ByVal hWnd1 As Long, ByVal hWnd2 As Long, _
- ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
- Private Declare PtrSafe Function GetDesktopWindow Lib "user32.dll" () As Long
- Sub test()
- Dim i As Long
- Dim arrXLhWnd() As Long
- If GetXLhWnds(arrXLhWnd) Then
- For i = LBound(arrXLhWnd) To UBound(arrXLhWnd)
- Debug.Print arrXLhWnd(i)
- Next
- End If
- End Sub
- Function GetXLhWnds(arrXLhWnd() As Long) As Long
- Dim n As Long
- Dim hWndXL As Long, hWndDT As Long
- ReDim arrXLhWnd(1 To 100) ' cater for 100 potential Excelinstances
- hWndDT = GetDesktopWindow
- Do
- hWndXL = FindWindowEx(hWndDT, hWndXL, "XLMAIN", vbNullString)
- If hWndXL Then
- n = n + 1
- arrXLhWnd(n) = hWndXL
- End If
- Loop Until hWndXL = 0
複製代碼 |
|