win32com, excel

Bob Gailer bgailer at alum.rpi.edu
Tue Aug 5 08:50:56 EDT 2003


At 10:54 AM 8/5/2003 +0200, Oliver Emrich wrote:

>I want to paste something from the clipboard in excel using python.
>
>I wrote a script but there occur errors during execution.
>The script looks like:
>
>import win32com.client
>
>xlApp = win32com.client.dynamic.Dispatch('Excel.Application')
>xlBook = xlApp.Workbooks.Open("C:/test.xls")
>xlSheet = xlBook.Worksheets("Test")
>xlSheet.Range(sht.Cells(1, 1), sht.Cells(1, 1)).Activate()
>xlSheet.Paste(1, 1)
>xlBook.Save()
>
>
>In VBA you just would write:
>ActiveSheet.Paste
>
>My problem is the Paste() method in Python. I think I need a Range object 
>but I don't know how to get it.

What is your understanding of the Paste arguments? Have you looked them up 
in Excel VBA help?

The equivalent of VBA Paste is Paste(). No arguments.

The first [optional] argument to Paste is a range object. Creating range 
objects is an Excel topic, not Python. Look up range object in Excel VBA help.

One way to create a range object in your example is: RangeObject = 
xlSheet.Range("A5")

Then the paste could be coded xlSheet.Paste(RangeObject)

Bob Gailer
bgailer at alum.rpi.edu
303 442 2625
-------------- next part --------------

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.506 / Virus Database: 303 - Release Date: 8/1/2003


More information about the Python-list mailing list