Jump to content

Copy/Paste excel cells until cell is blank


timmyc
 Share

Recommended Posts

Hey all,

Need a bit of a hand with this one. Essentially i am trying to copy an excel cell, paste it somewhere go back to excel, go down a cell and repeat until the cell is blank. I have a larger chunk of script that i will be using instead of this small task (copy and pasting into notepad) but i just wanted to loop something basic until i can get this working. 

This is my first time playing with AutoIt and excel. I suspect where i am going wrong is that i'm telling it to read a cell range in excel where as i need to tell it to read 1 cell at a time until cell = blank. Should i be adding in some logic where it increases the cell number each loop or should i be building an array from the column then calling back on those values?

 

#include <Array.au3>
#include <Excel.au3>
#include <MsgBoxConstants.au3>


;Essentially i am trying to copy an excel cell, paste it somewhere go back to excel, go down a cell and repeat untill the cell is blank

Local $oExcel = _Excel_Open()
Local $sWorkbook = @ScriptDir & "\Book1.xls"
Local $oWorkbook = _Excel_BookOpen($oExcel, $sWorkbook)

;Unsure if instead of using a cell range i should be getting excel to read one cell, then in the next loop add a 1 to the cell and read again. Eg. Read A1 do function, read A2 do function
Local $aResult = _Excel_RangeRead($oWorkbook,1, "A1:A14")

Do
   WinActivate("Microsoft Excel - Book1.xls")
   Send("{CTRLDOWN}c{CTRLUP}")
   ;Copy cell
   WinActivate("Untitled - Notepad")
   Send("{CTRLDOWN}v{CTRLUP}")
   ;Paste cell
   WinActivate("Microsoft Excel - Book1.xls")
   ;Go down a cell
   Send("{ENTER}{ENTER}")
Until $aResult = ""

Exit

Thanks for your help!

Link to comment
Share on other sites

Use a region as described in the wiki to read all cells until a blank cell is found. Then loop through the resulting array and send the cells to your application.

$oRange = $oWorkBook.Activesheet.Range("A1").CurrentRegion

 

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

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...