aamii wrote:第一个问题:
^c
第二个问题:
F9::
ControlFocus ,VbaWindow3,ahk_class wndclass_desked_gsk
ControlSend ,VbaWindow3,{CtrlDown}a{CtrlUp}{Delete},ahk_class wndclass_desked_gsk
return
这两个的方法都太土了.
还容易误操作.
找到一个曲线救国的.
VBcode=
(
Sub myFunction()
Worksheets(1).Range("C1").Value = 99
End Sub
)
Excel_Run("myFunction", VBcode) ; Changed: pass VBA code text to the function
return
Excel_Run(sFunction, VBcode){
;~ FilePath := C:\Users\KostasK\Desktop\Plano.xlsx
FilePath := A_ScriptDir "\Plano.xlsx" ; Changed for testing
oExcel := ComObjCreate("Excel.Application")
oExcel.Visible := true ; Changed for testing
oWorkbook := oExcel.Workbooks.Open(FilePath)
; We already have a reference to the Excel Application and Workbook objects. Don't need Excel_Get
Excel_ImportCode(VBcode, oWorkbook) ; Changed: Pass the workbook to use to Excel_ImportCode
oExcel.Run(sFunction) ; Changed
;~ oWorkbook.Save ; Changed for testing
;~ oExcel.Quit ; Changed for testing
}
Excel_ImportCode(VBcode, WorkbookObj){
if fileexist(A_ScriptDir . "\tempvbcode.txt")
FileDelete, %A_ScriptDir%\tempvbcode.txt
FileAppend, %VBcode%, %A_ScriptDir%\tempvbcode.txt
WorkbookObj.VBProject.VBComponents.Import(A_ScriptDir . "\tempvbcode.txt")
}