Jump to content

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

excel and com?


  • Please log in to reply
17 replies to this topic
Learning one
  • Members
  • 1483 posts
  • Last active: Jan 02 2016 02:30 PM
  • Joined: 04 Apr 2009
jethrow, I see your Excel_Get() was evolving over time. Is this the latest, most secure version?

and what do you recommend for MS Word, analog to Excel_Get() ? I'm using just this simple method;
#IfWinActive, ahk_class OpusApp
F3::
try
oDoc := ComObjActive("Word.Application").ActiveDocument
catch
return
oDoc.PageSetup.Orientation := 1    ; do something with active doc example (landscape orientation)
return
#IfWinActive
Should I use Acc_ObjectFromWindow() here too? If yes, could you please post Word_Get() version you recommend.

Thanks.

jethrow
  • Moderators
  • 2854 posts
  • Last active: May 17 2017 01:57 AM
  • Joined: 24 May 2009
The code can't really be called mine - I got it from Sean.

With Excel, each time you run excel via the start menu, a new Excel process is created. ComObjActive will access the first Excel Application object registered on the ROT - which may not be the Active Excel Window. This is different than the other MS Office Applications. When you open one of those via the start menu, it runs in the existing app process (if there is one). That's why, IMO, ComObjActive is prolly sufficient for Word, but not for Excel. However, you could use Acc_ObjectFromWindow with Word, if you wanted to:
ControlGet, hwnd, hwnd, , _WwG1, ahk_class OpusApp
Window := Acc_ObjectFromWindow(hwnd, -16)
MsgBox, % Window.Application.ActiveDocument.Range.Text


Learning one
  • Members
  • 1483 posts
  • Last active: Jan 02 2016 02:30 PM
  • Joined: 04 Apr 2009

The code can't really be called mine - I got it from Sean.

:lol: Ok. I usually like to write from who I picked up a function.

That's why, IMO, ComObjActive is prolly sufficient for Word, but not for Excel.

Ok, I'll be using ComObjActive for Word and Excel_Get() for Excel

Thank you! :) And thanks to Sean 8)