Advertisement
mgis90

ExcelGetCell.ahk

Jan 29th, 2016
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ;Returns currently selected cell (or range of cells) from Excel 2007
  2. ;you can place this script in Your Lib https://autohotkey.com/docs/Functions.htm#lib
  3. /*
  4. In Excel perform the following steps:
  5. -------------------------------------
  6. ctrl+F3     [Name Manager]  Window
  7. alt+n       [&New...]       Button -> opens "New Name" Window
  8. alt+r       [&Refers to:]       Edit box    (text will be selected)
  9. Ctrl+C      [system copy]       (or get this text any other way)
  10. Esc         [close alt+n]
  11. Esc         [close ctrl+f3]
  12.  
  13. the retrieved text will contain something like this when standing in a single cell before executing these steps:
  14. =NameOfWorksheet!$G$3
  15. where cell is G3
  16. -------------------------------------------
  17. -------------------------------------------
  18. Name Manager
  19. ahk_class bosa_sdm_XL9
  20. >>>>>>>>( Window Title & Class )<<<<<<<<<<<
  21. New Name
  22. ahk_class bosa_sdm_XL9
  23. >>>>>>>>>( Now Under Mouse Cursor )<<<<<<<<
  24. ClassNN:    EDTBX3
  25. Text:  
  26. >>>>( TitleMatchMode=slow Visible Text )<<<<
  27. =NameOfWorksheet!$G$3
  28. */
  29.  
  30. ExcelGetCell(auto:=1, WinTitle:="New Name ahk_class bosa_sdm_XL9", Control:="EDTBX3")
  31. {
  32.     if auto
  33.     {
  34.         IfWinActive,Microsoft Excel ahk_class XLMAIN
  35.         {
  36.             Send ^{F3}
  37.             Sleep 100
  38.             Send !n
  39.             Sleep 100
  40.         } else
  41.             return false
  42.     }
  43.     IfWinExist,%WinTitle%
  44.     {
  45.         ControlGetText, OutputVar, %Control%, %WinTitle%
  46.         if ErrorLevel
  47.             return false
  48.         if StrLen(OutputVar)<2
  49.             return false
  50.     } else
  51.         return false
  52.     if auto
  53.     {
  54.         Send {Esc}
  55.         Sleep 100
  56.         Send {Esc}
  57.     }
  58.     return OutputVar
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement