Autocopy selected text and auto paste in EXCEL

Get help with using AutoHotkey and its commands and hotkeys
djasi78
Posts: 27
Joined: 23 Feb 2018, 00:28

Autocopy selected text and auto paste in EXCEL

01 Mar 2018, 01:53

Hi, :D

I have 3 columns in excel file . :x

I want a script that can auto paste , the selected text [from pdf/web] (without manual copying /pasting ) in different columns. :shock:

Like , if i press 1 , it pastes the selected text in first column , 2 in 2nd column and 3 in 3rd column. :crazy:

Thanks :bravo:

:dance:
Johana
Posts: 189
Joined: 02 May 2017, 02:34

Re: Autocopy selected text and auto paste in EXCEL

01 Mar 2018, 02:52

So you copy ONE text and this should be pasted into either one of the 3 columns? You can do it with two different ways. 1 is to use soly AHK, which copies, activates Excel and pastes in the correct field. Or you can use the much better COM. I am not good with coding but I thought I'd tell you in which direction I would check.

But something like this?

Code: Select all

1:: ; Press the number 1
Sendinput, ^C ; Copy your selection
Xl := ComObjCreate("Excel.Application") ;
Xl.Visible := True ;by default excel sheets are invisible
Xl.Workbooks.Add ;add a new workbook
Xl.Range("A1").Value := clipboard ;Send clipboard to selected cell
return
User avatar
Xeo786
Posts: 299
Joined: 09 Nov 2015, 02:43
Location: Karachi, Pakistan

Re: Autocopy selected text and auto paste in EXCEL

01 Mar 2018, 03:13

below code Copy text to Excel's active cell then select next cell,

Code: Select all

f1::
send, ^C				; copy
clipwait				; wait for data to get copied completely sometime it take time depend on data
ComObjActive("Excel.Application").ActiveCell.value := clipboard ; data to excel active cell
ComObjActive("Excel.Application").ActiveCell.Offset(1,0).select ; select next cell where you paste next data
return
"When there is no gravity, there is absolute vacuum and light travel with no time" -Game changer theory
djasi78
Posts: 27
Joined: 23 Feb 2018, 00:28

Re: Autocopy selected text and auto paste in EXCEL

01 Mar 2018, 03:32

Thank you.

@Xeo786 , it is just pasting code in excel,not the selected text.
FanaticGuru
Posts: 1481
Joined: 30 Sep 2013, 22:25

Re: Autocopy selected text and auto paste in EXCEL

01 Mar 2018, 03:44

Johana wrote:So you copy ONE text and this should be pasted into either one of the 3 columns? You can do it with two different ways. 1 is to use soly AHK, which copies, activates Excel and pastes in the correct field. Or you can use the much better COM. I am not good with coding but I thought I'd tell you in which direction I would check.

But something like this?

Code: Select all

1:: ; Press the number 1
Sendinput, ^C ; Copy your selection
Xl := ComObjCreate("Excel.Application") ;
Xl.Visible := True ;by default excel sheets are invisible
Xl.Workbooks.Add ;add a new workbook
Xl.Range("A1").Value := clipboard ;Send clipboard to selected cell
return
Nice start but you probably don't want to use ComObjCreate as this will create a new Excel workbook each time.

Here is a more complete version that can handle 3 columns, putting the data in the first empty cell in each column.

Code: Select all

1::
2::
3::
	Column := A_ThisHotkey + 0	; force this to be treated as a number and not a string otherwise Excel will think you are looking for a column named the literal string 1
	SendInput ^c
	ClipWait,1	; wait up to 1 second for text to appear on clipboard
	if ErrorLevel	; something went wrong, abort
		return
	xlApp := ComObjActive("Excel.Application")	; use open Excel workbook
	xlCell_EmptyBelowData := xlApp.Columns(Column).Find("*",,,,,2).Offset(1,0)	; get cell just below last cell with anything in it
	if  !xlCell_EmptyBelowData.Address	; no cell found with anything in it, column is blank
		xlCell_EmptyBelowData := xlApp.Cells(1,Column)	; default to first cell
	xlCell_EmptyBelowData.Value := Clipboard
return
FG
Hotkey Help - Help Dialog for Currently Running AHK Scripts

AHK Startup - Consolidate Multiply AHK Scripts with one Tray Icon

[Function] Timer - Create and Manage Timers

Return to “Ask For Help”

Who is online

Users browsing this forum: Google [Bot], Noesis, TheNomadicAspie and 28 guests