Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old March 16th, 2006, 12:15 AM
koia
Guest
 
Posts: n/a
Default Excel ShapeRange problem with win32com

Hi,

I have a problem with adding attributes to a Line in an Excel drawing
using the Python win32com interface. From recording in Excel I get the
Macro:

Sub Makro1()
ActiveSheet.Shapes.AddLine(192.75, 63.75, 316.5, 110.25).Select
Selection.ShapeRange.Line.ForeColor.SchemeColor = 10
Selection.ShapeRange.Line.Visible = msoTrue
End Sub

I want to replicate this from Python24 using the win32com interface:

import win32com.client.dynamic
xlapp = win32com.client.dynamic.Dispatch("Excel.Applicatio n")
xlapp.Visible = True
xlbook = xlapp.Workbooks.Add()
xlapp.ActiveSheet.Shapes.AddLine( 0, 0, 100, 100).Select
<bound method CDispatch.Select of <COMObject AddLine>>

xlapp.Selection.ShapeRange.Line.ForeColor.SchemeCo lor = 10

This fails on ShapeRange, with output listed below. What can the
problem be? Is there a solution/work-around?

Thanks in advance
/koia

Traceback (most recent call last):
File "C:\Program Files\ActiveState Komodo
3.5\lib\support\dbgp\pythonlib\dbgp\client.py", line 3180, in runcode
locals = self.frame.f_locals)
File "C:\Program Files\ActiveState Komodo
3.5\lib\support\dbgp\pythonlib\dbgp\client.py", line 1574, in runcode
h_exec(code, globals=globals, locals=locals, module=module)
File "C:\Program Files\ActiveState Komodo
3.5\lib\support\dbgp\pythonlib\dbgp\client.py", line 516, in __init__
exec code in globals, locals
File "<console>", line 0, in __main__
File "C:\Python24\Lib\site-packages\win32com\client\dynamic.py", line
489, in __getattr__
raise AttributeError, "%s.%s" % (self._username_, attr)
AttributeError: <unknown>.ShapeRange

  #2  
Old March 16th, 2006, 01:55 AM
koia
Guest
 
Posts: n/a
Default Re: Excel ShapeRange problem with win32com

Sorry guys,

I forgot the parenthesis in

xlapp.ActiveSheet.Shapes.AddLine( 0, 0, 100, 100).Select()

/koia

 

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles