[python-win32] (no subject)

Tim Roberts timr at probo.com
Wed May 20 20:24:35 CEST 2009


Patrick Asselman wrote:
> How would i translate a bit of visual basic code like below to Python?
>
>     Range("F7").Select
>     Selection.Copy
>     Range("CO7").Select
>     Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _
>         SkipBlanks:=False, Transpose:=False
>
> I'm trying to copy the formatting of one cell to another cell. The
> above code is made with Excel macro.
>
> Is there any pywin32 documentation on the implementation of MS Office
> code in Python, or maybe on how one would go about to discover this?
> I've looked on the web but didn't find any definitive reference on this?

The main difference is that function calls in Python always require
parentheses, and the constants live in a different address space.  This
does what you do above (assuming Excel is already open):

    import win32com.client
    from win32com.client import constants
    excel = win32com.client.Dispatch("Excel.Application")
    excel.Range("F7").Select()
    excel.Selection.Copy()
    excel.Range("CO7").Select()
    excel.Selection.PasteSpecial( Paste=constants.xlPasteFormats )

The win32com.client constants only get imported if you have run makepy
on the Excel.Application typelib.

-- 
Tim Roberts, timr at probo.com
Providenza & Boekelheide, Inc.



More information about the python-win32 mailing list