Excel copy pasting

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
marsa
Posts: 25
Joined: 11 Jul 2018, 10:36

Excel copy pasting

23 Jul 2018, 08:25

Hi
I know I know, its like the bazilions thread about Excel :headwall:

If someone can find in there heart to help me anyway that would be swell.

Here is my code:

InputBox, kommun, Enter kommun,
LookFor := kommun


FilePath := A_Desktop "\Book1.xlsx" ; example path
oWorkbook := ComObjGet(FilePath) ; access Workbook object

; Get a Range object that represents the first cell in column N where the information is found.
; Then, using offset(Row, Col), get the text from the cell in column M directly left of the found cell.
FoundM := oWorkbook.Sheets(1).Range("N:N").Find(LookFor).Offset(0,1).Text

if (FoundM)
Send, ^c


As you can see, I want it to look in Excel document and search for the output from THE box, and if its found go to the cell to the right and copy that info. But i cant get it to work
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Excel copy pasting

24 Jul 2018, 17:31

- FoundM retrieves the text of the cell. So you could use 'Clipboard := ' instead of 'FoundM := '.
- Otherwise, a commented out line in the script below can be used to focus the cell. You can then send Ctrl+C.

Code: Select all

;Excel_Get - AutoHotkey Community
;https://autohotkey.com/boards/viewtopic.php?f=6&t=31840

q:: ;Excel - find cell, then get text of(/focus) adjacent cell
oXl := Excel_Get()
vNeedle := "abc"

;get text directly
Clipboard := oXl.Sheets(1).Range("N:N").Find(vNeedle).Offset(0,1).Text

;focus cell
;oXl.Sheets(1).Range("N:N").Find(vNeedle).Offset(0,1).Activate()

oXl := ""
return
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Google [Bot], Panaku, Rohwedder, roysubs and 308 guests