Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

AHK failure with Excel_Get ()


  • Please log in to reply
4 replies to this topic
lovika83
  • Members
  • 1 posts
  • Last active: Dec 21 2012 07:52 AM
  • Joined: 19 Dec 2012

I have been facing one problem whenever tried to run my AHK program overnight for some repititon tasks.

Basically my AHK flow is to read in some values from my Excel sheet and input those value into some software, and getting the software output value back into my Excel file.

 

This involves using

  Excel_Get([_WinTitle])               to activate my Excel file

  Excel_GetValue(_ID [, _start])   to read in my Excel value

  Excel_SetValue(_ID [, _start, _end, _value])     to enter output value into my Excel Sheet.

Below would be the detail script I get from this website.

 

 

Excel_Get(_WinTitle="ahk_class XLMAIN")
{
  ControlGet, hwnd, hwnd, , Excel71, %_WinTitle%
  return, Excel_Acc_ObjectFromWindow(hwnd, -16).Application
}

 

 

Excel_GetValue(_ID, _start="A1")
{
  If (StrLen(_start)<2)    
    Return 1
  Return _ID.Range(_start).value
}

 

 

Excel_SetValue(_ID, _start="A1", _end="", _value="")
{
  _end:=(_end=="") ? _start : _end
  If (StrLen(_start)<2 || StrLen(_end)<2)
    Return 1

  _ID.Range(_start ":" _end).value:=_value}

 

My AHK works properly on few repetitions. If I were to repeat my task for like thousand time.

My AHK scripts failed during the way. The error message specified that the above functions cannot be

called or rejected by callee.

 

I am not sure why this problems arise in my older PC but not my new PC.

The only clue I can think of is my PC spec. My old PC spec is having a RAM of 512MB while my new PC has

at least 4 GB. Is there any reason why these happen or how can I improve my AHK stability.

 

I am thinking of writing a short AHK to capture my PC memory space and reset or stop my AHK over some time interval

before continuing with my repitition task.

Any comment would be appreciate.

 

 



jethrow
  • Moderators
  • 2854 posts
  • Last active: May 17 2017 01:57 AM
  • Joined: 24 May 2009

I bet you're sheet is in Edit mode. You might try this:

Excel_Get(WinTitle="ahk_class XLMAIN", Excel7#=1) {
  WinGetClass, WinClass, %WinTitle%
  if (WinClass == "XLMAIN") {
    ControlGet, hwnd, hwnd, , Excel7%Excel7#%, %WinTitle%
    if Not ErrorLevel {
      window := Acc_ObjectFromWindow(hwnd, -16)
      if ComObjType(window) = 9
        while Not xl
          try xl := window.application
          catch e
            if SubStr(e.message,1,10) = "0x80010001"
              ControlSend, Excel7%Excel7#%, {Esc}, %WinTitle%
            else
              return "Error accessing the application object."
    }
  }
  return xl
}



Xia Mey
  • Members
  • 105 posts
  • Last active: Oct 01 2015 01:55 PM
  • Joined: 23 Dec 2012

Can you guys tell me why I can't use Excel_Get() please

 

This is my code

1 Xl := Excel_Get("Excel.Application")
or
2 Xl := Excel_Get()
or
3 Excel_Get("Excel.Application")
or
4 Excel_Get(WinTitle="Excel.Application")

Many thanks



flyingDman
  • Spam Officer
  • 2186 posts
  • Last active: Nov 07 2015 08:15 AM
  • Joined: 27 Feb 2009

I would recommend that you put Excel_Get code from jethrow in a file called Excel_get.ahk  and to put it in this folder: C:\Program Files (x86)\AutoHotkey\Lib\  (unless your autohotkey.exe is not in C:\Program Files (x86)\AutoHotkey\ ). You'll then always have access to Excel_Get(). If you do not put Excel_get.ahk in a library you need either to include the function in the script or use #include.
Then this code should be sufficient to get the content of cell A1:

Xl := Excel_Get()		                                
msgbox % Xl.Range("A1").value

Marine Corps Gen. Joseph Dunford told senators at his Joint Chiefs of Staff confirmation hearing : “If you want to talk about a nation that could pose an existential threat to the United States, I'd have to point to Russia. And if you look at their behavior, it's nothing short of alarming.”


Xia Mey
  • Members
  • 105 posts
  • Last active: Oct 01 2015 01:55 PM
  • Joined: 23 Dec 2012
I would recommend that you put Excel_Get code from jethrow in a file called Excel_get.ahk  and to put it in this folder: C:\Program Files (x86)\AutoHotkey\Lib\  (unless your autohotkey.exe is not in C:\Program Files (x86)\AutoHotkey\ ). You'll then always have access to Excel_Get(). If you do not put Excel_get.ahk in a library you need either to include the function in the script or use #include.
Then this code should be sufficient to get the content of cell A1:
Xl := Excel_Get()		                                
msgbox % Xl.Range("A1").value

#Include C:\Program Files\AutoHotkey\Excel_Get.ahk

but It still not work. I copy jethrow code and paste to a new note page and save as Excel_Get.ahk and store It to my AHK folder. above is what I tried.