well here's the code now:
Code:
COM_Init()
ControlGet, hwnd, hwnd, , Excel71, ahk_class XLMAIN ; get Control HWND
XLwin := COM_AccessibleObjectFromWindow(hwnd,-16) ; access Window COM Obj
pxl := COM_Invoke(XLwin, "Application"), COM_Release(XLwin) ; access the XL App
while COM_Invoke(pxl, "ActiveSheet.Range(""B1"").Value") = ""
sleep, 100
MsgBox,
COM_Release(pxl), COM_Term()
MsgBox, B1 updated, Done!
And I can click past the
msgbox, waiting on b1 and the program doesn't crash. I can then click in the spread sheet, and move around with the mouse or arrow buttons, the on the first keystroke on any cell of the sheet, it doesn't even have to be cell B1, I get:
------------------------------------ X
COM Error Notification
Function Name: "ActiveSheet"
ERROR: Call was rejected by callee.
(0x80010001)
Will Continue?
Yes No
---------------------------------------
I've tried both syntax statements for the while statement:
Code:
;while COM_Invoke(pxl, "ActiveSheet.Range(""B1"").Value") = ""
while COM_Invoke(pxl, "ActiveSheet.Range[b1].Value") = ""
-jon
Latest full script (not working):
Code:
; Orbiter_runner program.
; -This is a test runner program for excel. it just loads up 10 numbers in the first column
; and then adds the "=row()" function to the 11th row.
;
;
;100805 JL First creation. By including the Com.ahk library, we can call ~ something ~ (VB??)
; to get run all kinds of goodies in the excel world. I would like to:
;
; 1) get the row count used and return it to a variable in this script.
; 2) read a cell and return its value to a variable in this script.
;
;
;
;
;
;
; AutoHotkey Version: 1.x
; Language: English
; Platform: Win9x/NT
; Author: A.N.Other <myemail@nowhere.com>
;
; Script Function:
; Template script (you can customize this template by editing "ShellNew\Template.ahk" in your Windows folder)
;
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
#include %a_scriptdir%\com.ahk
Run, excel, C:\My Documents, max, exl_pid
; lets set up some data, we will load the last row with the "=row()" function, but this may not
; be the best way to get the row count.
WinWait, Microsoft Excel ,
IfWinNotActive, Microsoft Excel , , WinActivate, Microsoft Excel ,
WinWaitActive, Microsoft Excel ,
MouseClick, left, 506, 13
Sleep, 100
Send, {F5}
WinWait, Go To,
IfWinNotActive, Go To, , WinActivate, Go To,
WinWaitActive, Go To,
Send, a1{ENTER}
WinWait, Microsoft Excel ,
IfWinNotActive, Microsoft Excel , , WinActivate, Microsoft Excel ,
WinWaitActive, Microsoft Excel ,
Sleep, 50
Send, 5{ENTER}
Sleep, 50
Send,5{ENTER}
Sleep, 50
Send,2{ENTER}
Sleep, 50
Send,4{ENTER}
Sleep, 50
Send,6{ENTER}
Sleep, 50
Send,5{ENTER}
Sleep, 50
Send,3{ENTER}
Sleep, 50
Send,6{ENTER}
Sleep, 50
Send,9{ENTER}
Sleep, 50
Send,10{ENTER}
Sleep, 50
Send,{CTRLDOWN}{HOME}{CTRLUP}
Sleep, 50
Send,{CTRLDOWN}{END}{CTRLUP}
Sleep, 50
Send,{DOWN}
Sleep, 50
Send,=row{SHIFTDOWN}90{SHIFTUP}{ENTER}
Sleep, 50
FileReadLine, line, C:\testfile.txt, 1
; ok we have data how do we retrieve the number of rows back into a variable of this script?
msgbox, waiting on B1.%line%.
; doesn't work, something about invisbile execl and no activeworksheet
;COM_Init()
;pxl := COM_GetActiveObject("Excel.Application")
;while COM_Invoke(pxl, "ActiveSheet.Range(""$B$1"").Value") = ""
; sleep, 100
;COM_Release(pxl), COM_Term()
COM_Init()
ControlGet, hwnd, hwnd, , Excel71, ahk_class XLMAIN ; get Control HWND
XLwin := COM_AccessibleObjectFromWindow(hwnd,-16) ; access Window COM Obj
pxl := COM_Invoke(XLwin, "Application"), COM_Release(XLwin) ; access the XL App
;while COM_Invoke(pxl, "ActiveSheet.Range(""B1"").Value") = ""
while COM_Invoke(pxl, "ActiveSheet.Range[b1].Value") = ""
sleep, 100
MsgBox,
COM_Release(pxl), COM_Term()
MsgBox, B1 updated, Done!
msgbox, runner done(%0%).`n%1%`n%2%`n%3%`n
exitapp, 5000
; end of program.