Hi,
I have 3 columns in excel file .
I want a script that can auto paste , the selected text [from pdf/web] (without manual copying /pasting ) in different columns.
Like , if i press 1 , it pastes the selected text in first column , 2 in 2nd column and 3 in 3rd column.
Thanks
Autocopy selected text and auto paste in EXCEL
Re: Autocopy selected text and auto paste in EXCEL
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?
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
Re: Autocopy selected text and auto paste in EXCEL
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
Re: Autocopy selected text and auto paste in EXCEL
Thank you.
@Xeo786 , it is just pasting code in excel,not the selected text.
@Xeo786 , it is just pasting code in excel,not the selected text.
- FanaticGuru
- Posts: 1907
- Joined: 30 Sep 2013, 22:25
Re: Autocopy selected text and auto paste in EXCEL
Nice start but you probably don't want to use ComObjCreate as this will create a new Excel workbook each time.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
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
Hotkey Help - Help Dialog for Currently Running AHK Scripts
AHK Startup - Consolidate Multiply AHK Scripts with one Tray Icon
Hotstring Manager - Create and Manage Hotstrings
[Class] WinHook - Create Window Shell Hooks and Window Event Hooks
AHK Startup - Consolidate Multiply AHK Scripts with one Tray Icon
Hotstring Manager - Create and Manage Hotstrings
[Class] WinHook - Create Window Shell Hooks and Window Event Hooks
Who is online
Users browsing this forum: Bing [Bot] and 144 guests