Sign in to follow this  
Followers 0
modernes

Copy-paste issues in excel

2 posts in this topic

Hi,

I am trying to create a script that will (1)copy one cell and (2)paste the info into an empty cell in excel in a list until the list(1) is complete. I am finding that using the send function is not working very well to copy and paste the data. Any ideas?

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Hi,

I am trying to create a script that will (1)copy one cell and (2)paste the info into an empty cell in excel in a list until the list(1) is complete. I am finding that using the send function is not working very well to copy and paste the data. Any ideas?

Absolutely. Have a look at the UDF proposal link in my signature. Download that, place it in your \Include or script directory, and you'll have a decent package of functions to help you automate Excel, including copy & paste.

Unfortunately, I don't yet have any new example programs to help show you how to use the functions - so here's the basics on how a task such as yours would be done:

#include <ExcelCOM_UDF.au3>   ; include the UDF

; Open your Excel workbook as an object and make it visible
$oBook = _ExcelBookOpen("C:\The_Excel_File.xls", 1)  ; replace the filepath with your own

; Copy and paste a range of cells to another location
_ExcelCopy($oBook, "A1:A999")  ; you can use R1C1 format, too - check the function's header for syntax
_ExcelPaste($oBook, "B1")

; Save and close the workbook
_ExcelBookClose($oBook)

To copy & paste based on a range you don't know the size of at runtime, you could create a loop that checks each individual cell in your list with _ExcelRead() to see if it is empty or whatever, and once you figure out where the end of your list is, perform the copy. That would require using R1C1 cell addressing to make iterating through the cells easier.

Hope that helps.

-S

Edited by Locodarwin

(Yet Another) ExcelCOM UDF"A human being should be able to change a diaper, plan an invasion, butcher a hog, conn a ship, design a building, write a sonnet, balance accounts, build a wall, set a bone, comfort the dying, take orders, give orders, cooperate, act alone, solve equations, analyze a new problem, pitch manure, program a computer, cook a tasty meal, fight efficiently, die gallantly...[indent]...specialization is for insects." - R. A. Heinlein[/indent]

Share this post


Link to post
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
Sign in to follow this  
Followers 0