#SingleInstance force
#Include Acc.ahk
VBcode=
(
Sub myFunction()
Worksheets(1).Select
Worksheets(1).Range("C1").Select
Selection.Value = 99
End Sub
)
Excel_Run("myFunction")
Excel_Run(sFunction){
FilePath = C:\Users\KostasK\Desktop\Plano.xlsx
oExcel := ComObjCreate("Excel.Application")
Excel_ImportCode(VBcode)
oWorkbook := oExcel.Workbooks.Open(FilePath)
Excel_Get().Run(sFunction)
oWorkbook.Save
oExcel.Quit
}
Excel_ImportCode(VBcode){
if fileexist(A_ScriptDir . "\tempvbcode.txt")
FileDelete, %A_ScriptDir%\tempvbcode.txt
FileAppend, %VBcode%, %A_ScriptDir%\tempvbcode.txt
Excel_Get().ActiveWorkbook.VBProject
.VBComponents.Import(A_ScriptDir . "\tempvbcode.txt")
}
Excel_Get(WinTitle="ahk_class XLMAIN") { ; by Sean and Jethrow, minor modification by Learning one
ControlGet, hwnd, hwnd, , Excel71, %WinTitle%
if !hwnd
return
Window := Acc_ObjectFromWindow(hwnd, -16)
Loop
try
Application := Window.Application
catch
ControlSend, Excel71, {esc}, %WinTitle%
Until !!Application
return Application
}
学习学习