Jump to content

Script to copy Excel cell content and paste in another programe - (Moved)


ANSHQ01
 Share

Recommended Posts

Hello Experts,

This is my 1st post, I have watched YouTube Videos to train myself on Autoit.   For simple task faced, it appears to be Rocket science for me.

I am trying to copy cell  content (Microsoft Office 2019) and paste it to another platform (control + tab) and hit enter.

Observer the result and come back to Excel (control + tab)  to select second cell A2 paste, and observer results...    repeat this till I reach last row normally 15,000 to 16000 rows

 Currently I am doing manually and use Microsoft Edge.

Any helpful guidance/codes will be appreciated. 

 Cheers

 

Link to comment
Share on other sites

  • Moderators

Moved to the appropriate AutoIt General Help and Support forum, as the Developer General Discussion forum very clearly states:

Quote

General development and scripting discussions.


Do not create AutoIt-related topics here, use the AutoIt General Help and Support or AutoIt Technical Discussion forums.

Moderation Team

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Take a look at the function_Excel_RangeRead in the help file. Using it, you could read the contents of the Excel file into an array, which you could then process to avoid the flipping back and forth between applications. If you search the forum, then you should find some examples of this function.

 

Link to comment
Share on other sites

Usually, we ask members to make an effort to create a starting script, and help them from there.  But since it is quite a challenging script for a novice, and it will sure help you in your job and we are in Chrismas time, here my gift for you :

#include <Excel.au3>
#include <Constants.au3>

Global Const $START = 2  ; <========= starting row to begin reading from your excel sheet

Global $oWorkBook = _Excel_BookAttach("Book1.xls", "filename") ; <==== your excel file name here
If @error Then Exit MsgBox($MB_OK, "Error", "Excel sheet not loaded")
Global $iLastRow = $oWorkbook.ActiveSheet.Usedrange.Rows.Count
Global $aList = _Excel_RangeRead($oWorkBook, Default, "A" & $START & ":A" & $iLastRow) ; Read column A from START to end
If @error or Not IsArray($aList) Then Exit MsgBox($MB_OK, "Error", "unable to read column from excel sheet")
_ArrayDisplay($aList) ; Display content of column A

HotKeySet("{PGDN}", CopyNextCell)  ; PageDown to copy next cell into your other app
HotKeySet("^+{END}", Terminate)    ; ctrl-shift-end to exit your script

While Sleep(100)
WEnd

Func Terminate()
  Exit
EndFunc

Func CopyNextCell()
  Local Static $iPos = 0
  Local $hWnd = WinActivate("[CLASS:Notepad]") ; <======= "Your app title here"
  If Not $hWnd Then Exit MsgBox($MB_OK, "Error", "Application not loaded")
  WinWaitActive($hWnd)

  Send("^a{DEL}" & $aList[$iPos])
  ;ControlSetText($hWnd, "", "Your control name here", $aList[$iPos]) ; LOT better but you need to find the control with au3info.exe
  $iPos += 1
  If $iPos > $iLastRow - $START Then Exit MsgBox($MB_OK, "Warning", "Last row reached, exiting script")
EndFunc

You need to load both excel sheet and your application, modify script accordingly to fit excel file name and app title.

_ArrayDisplay will show you the content of the column of your excel sheet

Press PgDn key to copy each cell (one a time) into your app

Edited by Nine
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...