win32com ppt embedded object

Discussion in 'Python' started by Lance Hoffmeyer, Jul 10, 2007.

  1. Hey all,

    I am trying to create some python code to edit embedded ppt slides and need some help.

    import win32com.client
    from win32com.client import constants
    import re
    import codecs,win32com.client
    import time
    import datetime
    import win32com.client.dynamic
    ######################################################
    ############ VARIOUS VARIABLES TO SET ################
    path = "C:\temp/"
    ######################################################
    ######################################################


    PPT=win32com.client.Dispatch("PowerPoint.Application")
    WB=PPT.Presentations.Open(path + "File.ppt")
    PPT.Visible=1
    PPTSLIDE= 29

    for Z in WB.Slides(29).Shapes:
    if (Z.Type== 7):
    ZZ=Z.OLEFormat.Object
    WSHEET = ZZ.Worksheets(1)
    WSHEET.Range("A1").Value = .50
    WSHEET.Range("A1").NumberFormat="0%"

    Gives error:

    Traceback (most recent call last):
    File "P:\Burke\TRACKERS\Ortho-McNeil\04 2007, 04-10 WAVE 4\Automation\Document1.py", line 23, in ?
    WSHEET = ZZ.Worksheets(1)
    File "C:\Program Files\Python\lib\site-packages\win32com\client\dynamic.py", line 489, in __getattr__
    raise AttributeError, "%s.%s" % (self._username_, attr)
    AttributeError: <unknown>.Worksheets

    Tool completed with exit code 1



    Why is ZZ unknown and how to I correct this?




    Thanks in advance,

    Lance
     
    Lance Hoffmeyer, Jul 10, 2007
    #1
    1. Advertising

  2. Lance Hoffmeyer

    fynali Guest

    On Jul 10, 8:40 pm, Lance Hoffmeyer <> wrote:
    > Hey all,
    >
    > I am trying to create some python code to edit embedded ppt slides and need some help.
    >
    > import win32com.client
    > from win32com.client import constants
    > import re
    > import codecs,win32com.client
    > import time
    > import datetime
    > import win32com.client.dynamic
    > ######################################################
    > ############ VARIOUS VARIABLES TO SET ################
    > path = "C:\temp/"
    > ######################################################
    > ######################################################
    >
    > PPT=win32com.client.Dispatch("PowerPoint.Application")
    > WB=PPT.Presentations.Open(path + "File.ppt")
    > PPT.Visible=1
    > PPTSLIDE= 29
    >
    > for Z in WB.Slides(29).Shapes:
    > if (Z.Type== 7):
    > ZZ=Z.OLEFormat.Object
    > WSHEET = ZZ.Worksheets(1)
    > WSHEET.Range("A1").Value = .50
    > WSHEET.Range("A1").NumberFormat="0%"
    >
    > Gives error:
    >
    > Traceback (most recent call last):
    > File "P:\Burke\TRACKERS\Ortho-McNeil\04 2007, 04-10 WAVE 4\Automation\Document1.py", line 23, in ?
    > WSHEET = ZZ.Worksheets(1)
    > File "C:\Program Files\Python\lib\site-packages\win32com\client\dynamic.py", line 489, in __getattr__
    > raise AttributeError, "%s.%s" % (self._username_, attr)
    > AttributeError: <unknown>.Worksheets
    >
    > Tool completed with exit code 1
    >
    > Why is ZZ unknown and how to I correct this?
    >
    > Thanks in advance,
    >
    > Lance



    """
    How do I know which methods and properties are available?
    Good question. This is hard! You need to use the documentation with
    the products, or possibly a COM browser. Note however that COM
    browsers typically rely on these objects registering themselves in
    certain ways, and many objects to not do this. You are just expected
    to know.

    The Python COM browser
    PythonCOM comes with a basic COM browser that may show you the
    information you need. Note that this package requires Pythonwin (ie,
    the MFC GUI environment) to be installed for this to work.

    There are far better COM browsers available - I tend to use the one
    that comes with MSVC, or this one!

    To run the browser, simply select it from the Pythonwin Tools menu, or
    double-click on the file win32com\client\combrowse.py

    """

    --
    s|a fynali
     
    fynali, Jul 10, 2007
    #2
    1. Advertising

  3. Re: win32com ppt embedded object - SOLVED

    Basically,
    if I ran (after discovering what the object name I was trying to modify in the ppt slide was):

    if WB.Slides(29).Shapes("Object 2").Type==7:
    PWB = WB.Slides(29).Shapes("Object 2") #Select the Graph Object
    oGraph = PWB.OLEFormat.Object
    oGraph.Application.datasheet.Range("00").Value = "Fav"

    this code worked.


    When I ran this:

    for shape in WB.Slides(29).Shapes:
    if (shape.Type== 7):
    print shape.Name
    PWB = WB.Slides(29).Shapes(shape)
    oGraph = PWB.OLEFormat.Object
    oGraph.Application.datasheet.Range("00").Value = "Fav"


    I got an error.


    I tried "print shape" I received

    <win32com.gen_py.Microsoft PowerPoint 11.0 Object Library.Shape instance at 0x17793112>


    Putting in PWB = WB.Slides(29).Shapes(shape.Name) instead of PWB = WB.Slides(29).Shapes(shape)
    allowed this to work.

    Also, I discovered I was working with a MSGraph object and not an Excel spreadsheet object.

    for shape in WB.Slides(29).Shapes:
    if (shape.Type== 7):
    print shape.Name
    PWB = WB.Slides(29).Shapes(shape.Name)
    oGraph = PWB.OLEFormat.Object
    oGraph.Application.datasheet.Range("00").Value = "Fav"

    Lance






    Lance Hoffmeyer wrote:
    > Hey all,
    >
    > I am trying to create some python code to edit embedded ppt slides and need some help.
    >
    > import win32com.client
    > from win32com.client import constants
    > import re
    > import codecs,win32com.client
    > import time
    > import datetime
    > import win32com.client.dynamic
    > ######################################################
    > ############ VARIOUS VARIABLES TO SET ################
    > path = "C:\temp/"
    > ######################################################
    > ######################################################
    >
    >
    > PPT=win32com.client.Dispatch("PowerPoint.Application")
    > WB=PPT.Presentations.Open(path + "File.ppt")
    > PPT.Visible=1
    > PPTSLIDE= 29
    >
    > for Z in WB.Slides(29).Shapes:
    > if (Z.Type== 7):
    > ZZ=Z.OLEFormat.Object
    > WSHEET = ZZ.Worksheets(1)
    > WSHEET.Range("A1").Value = .50
    > WSHEET.Range("A1").NumberFormat="0%"
    >
    > Gives error:
    >
    > Traceback (most recent call last):
    > File "P:\Burke\TRACKERS\Ortho-McNeil\04 2007, 04-10 WAVE 4\Automation\Document1.py", line 23, in ?
    > WSHEET = ZZ.Worksheets(1)
    > File "C:\Program Files\Python\lib\site-packages\win32com\client\dynamic.py", line 489, in __getattr__
    > raise AttributeError, "%s.%s" % (self._username_, attr)
    > AttributeError: <unknown>.Worksheets
    >
    > Tool completed with exit code 1
    >
    >
    >
    > Why is ZZ unknown and how to I correct this?
    >
    >
    >
    >
    > Thanks in advance,
    >
    > Lance
    >
    >
     
    Lance Hoffmeyer, Jul 11, 2007
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Gaurav
    Replies:
    2
    Views:
    405
  2. Replies:
    3
    Views:
    14,684
    Steve Rindsberg
    Jan 22, 2005
  3. Lance Hoffmeyer

    win32com ppt saveas, not allowing spaces?

    Lance Hoffmeyer, Jul 16, 2007, in forum: Python
    Replies:
    3
    Views:
    534
    supercooper
    Jul 23, 2007
  4. Lance Hoffmeyer
    Replies:
    2
    Views:
    551
    Lance Hoffmeyer
    Jul 26, 2007
  5. Lance Hoffmeyer
    Replies:
    0
    Views:
    275
    Lance Hoffmeyer
    Nov 17, 2003
Loading...

Share This Page