假如要跟EXCEL直接連結,用VBA來做如下,看看有其他比較好的作法。
1. 用 sendkeys "% ": sendkeys "x" 的方法也可以放到最大,但視窗的位置在不同的螢幕的定位表現有不一樣。
2. 匯入的結果檔案位置在 C:\... \TWEWinner\???.csv; 有時是 直接出現在 獨立的 Excel.application 的 一個檔案視窗 (這是在不同電腦執行的結果,有待先 進解惑)
'================================================================================================
Option Explicit
Public Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Public Declare Function GetSystemMetrics Lib "user32.dll" (ByVal index As Long) As Long '獲取顯示器銀幕大小
Private Declare Function SetCursorPos Lib "user32" (ByVal x As Long, ByVal y As Long) As Long '移動 cursor 到指定位置
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function GetWindowRect Lib "user32" (ByVal Hwnd As Long, lpRECT As RECT) As Long
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Dim lpRECT As RECT
Private Declare Function MoveWindow Lib "user32" ( _
ByVal Hwnd As Long, _
ByVal x As Long, _
ByVal y As Long, _
ByVal nWidth As Long, _
ByVal nHeight As Long, _
ByVal bRepaint As Long _
) As Long
Private Declare Sub mouse_event Lib "user32" (ByVal dwFlags As Long, ByVal dx As Long, ByVal dy As Long, ByVal cButtons As Long, ByVal dwExtraInfo As Long)
'在點金靈看圖軟體 的 "[6000]技術線圖" 點按 Excel圖示
'匯出 線圖資料
'===========================================
Sub 技術線圖匯出_Click()
Dim wb As Workbook
AppActivate "[6000] 技術線圖"
Sleep 1000
視窗最大化
SetCursorPos 1835, 46 'Excel圖示 的點按位置座標
Sleep (500)
MouseLeft_Click 'leftClick on he Excel logo
Sleep (1000) '緩衝時間使資料輸出到 Excel 工作表
視窗還原
Sleep (150)
End Sub
Sub 視窗最大化()
Dim Hwnd&
Dim x0&, y0&
x0 = GetSystemMetrics(0)
y0 = GetSystemMetrics(1)
Hwnd = FindWindow("TFormPackage", "[6000] 技術線圖")
GetWindowRect Hwnd, lpRECT '保留視窗原來大小尺寸
MoveWindow Hwnd, 0, 0, x0, y0, True '至左頂並放至最大
End Sub
Sub 視窗還原()
Dim Hwnd&
Hwnd = FindWindow("TFormPackage", "[6000] 技術線圖")
MoveWindow Hwnd, lpRECT.Left, lpRECT.Top, lpRECT.Right - lpRECT.Left, lpRECT.Bottom - lpRECT.Top, True 'Lefttop and width, height 'Lefttop and width, height
End Sub
Sub MouseLeft_Click() '模擬按滑鼠左鍵
mouse_event 2, 0, 0, 0, 0
Sleep (200)
mouse_event 4, 0, 0, 0, 0
Sleep (150)
End Sub