Sign in to follow this  
Followers 0
Jewtus

PowerPoint COM object trouble

34 posts in this topic

#1 ·  Posted (edited)

I've been playing with this UDF

'?do=embed' frameborder='0' data-embedContent>>

but I only need a couple functions from the script and I'd like to avoid additional includes, so this is what I've done:

$objPPT = ObjCreate("PowerPoint.Application")
If @error Then
    MsgBox(0,"","No PowerPoint available")
    Exit
EndIf

$objPPT.Visible = False
$objPPT.Presentations.Open(@ScriptDir&"\test.potx")
$objPPT.Shapes.AddTextBox(1,5,5,100,50)
$objPPT.Shapes.Item(1).TextFrame.TextRange.Text = "this is a test"
MsgBox(0,"","did it work?")
$objPPT.SaveAs("C:\Users\TEMP\Downloads\Output.ppt")
$objPPT.Quit

The parts that don't seem to work are:

$objPPT.Shapes.AddTextBox(1,5,5,100,50)
$objPPT.Shapes.Item(1).TextFrame.TextRange.Text = "this is a test"

and

$objPPT.Visible = False
 

and

$objPPT.SaveAs("C:UsersTEMPDownloadsOutput.ppt")
 

Does anyone have any idea what I'm doing wrong? Maybe someone can point me to a PPT COM object cheatsheet?

Also, How do I figure out what index things that are already on the PPT are?

Edited by Jewtus

Share this post


Link to post
Share on other sites



 

The parts that don't seem to work are:

What do you mean by "don't work"? Error messages, return codes, script crash ...?


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

 

Excellent! Thanks. I'll keep looking into this

What do you mean by "don't work"? Error messages, return codes, script crash ...?

 

It doesn't crash, nor do I get a return code. It just seems to skip over them... Is there a way to monitor the COM object so I can actually see what the returned error is?

I did update it and it does work a little bit better now:

$objPPT = ObjCreate("PowerPoint.Application")
If @error Then
    MsgBox(0,"","No PowerPoint available")
    Exit
EndIf

$objPPT.Visible = False ;Doesn't work... window still shows up
$objPPT.Presentations.Open(@ScriptDir&"\test.potx") ; Works, PPT opens
$PPT=$objPPT.ActivePresentation.Slides(1)
With $PPT.Shapes.AddTextBox(1,5,5,100,50) ; Works, creates the text box
MsgBox(0,"","did it work?")
$objPPT.SaveAs ("C:\Users\TEMP\Downloads\Output.ppt") ; doesn't work, doesn't save the file
$objPPT.Quit ; works, closes powerpoint

Share this post


Link to post
Share on other sites

$objPPT = ObjCreate("PowerPoint.Application")
If @error Then Exit MsgBox(0,"","No PowerPoint available")
$objPPT.Visible = False ;Doesn't work... window still shows up
If @error Then Exit MsgBox(0,"","Visible. @error = " & @error & ", @extended = " & @extended)
$objPPT.Presentations.Open(@ScriptDir&"\test.potx") ; Works, PPT opens
If @error Then Exit MsgBox(0,"","Open. @error = " & @error & ", @extended = " & @extended)
$PPT=$objPPT.ActivePresentation.Slides(1)
If @error Then Exit MsgBox(0,"","Slides. @error = " & @error & ", @extended = " & @extended)
With $PPT.Shapes.AddTextBox(1,5,5,100,50) ; Works, creates the text box
If @error Then Exit MsgBox(0,"","AddTextBox. @error = " & @error & ", @extended = " & @extended)
MsgBox(0,"","did it work?")
$objPPT.SaveAs ("C:\Users\TEMP\Downloads\Output.ppt") ; doesn't work, doesn't save the file
If @error Then Exit MsgBox(0,"","SaveAs. @error = " & @error & ", @extended = " & @extended)
$objPPT.Quit ; works, closes powerpoint
If @error Then Exit MsgBox(0,"","Quit. @error = " & @error & ", @extended = " & @extended)

What do you get?


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

$objPPT = ObjCreate("PowerPoint.Application")
If @error Then Exit MsgBox(0,"","No PowerPoint available")
$objPPT.Visible = False ;Doesn't work... window still shows up
If @error Then Exit MsgBox(0,"","Visible. @error = " & @error & ", @extended = " & @extended)
$objPPT.Presentations.Open(@ScriptDir&"\test.potx") ; Works, PPT opens
If @error Then Exit MsgBox(0,"","Open. @error = " & @error & ", @extended = " & @extended)
$PPT=$objPPT.ActivePresentation.Slides(1)
If @error Then Exit MsgBox(0,"","Slides. @error = " & @error & ", @extended = " & @extended)
With $PPT.Shapes.AddTextBox(1,5,5,100,50) ; Works, creates the text box
If @error Then Exit MsgBox(0,"","AddTextBox. @error = " & @error & ", @extended = " & @extended)
MsgBox(0,"","did it work?")
$objPPT.SaveAs ("C:\Users\TEMP\Downloads\Output.ppt") ; doesn't work, doesn't save the file
If @error Then Exit MsgBox(0,"","SaveAs. @error = " & @error & ", @extended = " & @extended)
$objPPT.Quit ; works, closes powerpoint
If @error Then Exit MsgBox(0,"","Quit. @error = " & @error & ", @extended = " & @extended)

What do you get?

I get a syntax error...

>Running AU3Check (3.3.10.2)  from:H:toolsAutoit - Portableautoit-v3install  input:C:UsersTEMPDesktopPPT_Example.au3

"C:UsersTEMPDesktopPPT_Example.au3"(39,90) : error: syntax error

If @error Then Exit MsgBox(0,"","Quit. @error = " & @error & ", @extended = " & @extended)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^

C:UsersTEMPDesktopPPT_Example.au3 - 1 error(s), 0 warning(s)

I commented out that line and the syntax error just moved up.

EDIT: I left a with in the wrong spot... got rid of the error syntax and used console write on the variable (so I could paste them here)

$objPPT = ObjCreate("PowerPoint.Application")
If @error Then
    MsgBox(0,"","No PowerPoint available")
    Exit
EndIf

$objPPT.Visible = False ;Doesn't work... window still shows up
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $objPPT.Visible = ' & $objPPT.Visible & @CRLF & '>Error code: ' & @error & @CRLF &@extended) ;### Debug Console
$objPPT.Presentations.Open(@ScriptDir&"\test.potx") ; Works, PPT opens
$PPT=$objPPT.ActivePresentation.Slides(1)
$PPT.Shapes.AddTextBox(1,5,5,100,50) ; Works, creates the text box
MsgBox(0,"","did it work?")
$objPPT.SaveAs ("C:\Users\TEMP\Downloads\Output.ppt") ; doesn't work, doesn't save the file
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $objPPT.SaveAs = ' & $objPPT.SaveAs & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console
$objPPT.Quit ; works, closes powerpoint

this was the error outputs:

@@ Debug(8) : $objPPT.Visible = 0

>Error code: 0

0@@ Debug(14) : $objPPT.SaveAs =

>Error code: -2147352570

Edited by Jewtus

Share this post


Link to post
Share on other sites

I'm sure you can't save the application object. You need to save the presentation.

Something like this (untested):

$objPPT = ObjCreate("PowerPoint.Application")
If @error Then
    MsgBox(0,"","No PowerPoint available")
    Exit
EndIf

$objPPT.Visible = False ;Doesn't work... window still shows up
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $objPPT.Visible = ' & $objPPT.Visible & @CRLF & '>Error code: ' & @error & @CRLF &@extended) ;### Debug Console
$oPresentation = $objPPT.Presentations.Open(@ScriptDir&"\test.potx") ; Works, PPT opens
$PPT=$objPPT.ActivePresentation.Slides(1)
$PPT.Shapes.AddTextBox(1,5,5,100,50) ; Works, creates the text box
MsgBox(0,"","did it work?")
$oPresentation.SaveAs ("C:\Users\TEMP\Downloads\Output.ppt") ; doesn't work, doesn't save the file
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $objPPT.SaveAs = ' & $objPPT.SaveAs & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console
$objPPT.Quit ; works, closes powerpoint

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

Ya I managed to figure out what was going on... it was my syntax. I was calling the wrong string but I was able to figure it out:

$oMyError = ObjEvent("AutoIt.Error","MyErrFunc")

$objPPT = ObjCreate("PowerPoint.Application")
If @error Then
    MsgBox(0,"","No PowerPoint available")
    Exit
EndIf

AddSlide(2,11,"Example Project")
Func AddSlide($slideNum,$format,$projectName)
    $PPT=$objPPT.Presentations.Open("C:\Users\TEMP\Desktop\test.potx")
    $objSlide1 = $PPT.Slides.Add($slideNum,$format)
    $objSlide1.Shapes.Item(1).TextFrame.TextRange.Text = $projectName
    $objSlide1.Shapes.AddTextBox(1,35,60,400,50)
    $objSlide1.Shapes.Item(2).TextFrame.TextRange.Text = "Overall Status"
    $objSlide1.Shapes.AddTextBox(1,300,60,400,50)
    $objSlide1.Shapes.Item(3).TextFrame.TextRange.Text = "Issues"
EndFunc
$objPPT.Quit ; works, closes powerpoint
Edited by Jewtus

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

I was wondering if anyone could let me know how to get around autoit trying to use this as a function call:

$objPPT = ObjCreate("PowerPoint.Application")
If @error Then
    MsgBox(0,"","No PowerPoint available")
    Exit
EndIf

AddSlide(2,11,"Example Project")
Func AddSlide($slideNum,$format,$projectName)
    $PPT=$objPPT.Presentations.Open("C:\Users\TEMP\Desktop\test.potx")
    $rows=10
    $cols=3
    $objSlide1 = $PPT.Slides.Add($slideNum,$format)
    With $objSlide1
        .Shapes.Item(1).TextFrame.TextRange.Text = $projectName
        .Shapes.AddTextBox(1,35,60,400,50) ;type,left,top,width,height
        .Shapes.Item(2).TextFrame.TextRange.Text = "Overall Status"
        .Shapes.AddTextBox(1,300,60,400,50)
        .Shapes.Item(3).TextFrame.TextRange.Text = "Issues"
        .Shapes.AddTextBox(1,500,60,400,50)
        .Shapes.Item(4).TextFrame.TextRange.Text = "Next Week"
        .Shapes.AddShape(151,30,100,200,200)
        .Shapes.Item(5).Fill.ForeColor.RGB= RGB(125,125,125)
        .Shapes.AddTable($rows,$cols,60,120,100,100)
    EndWith
EndFunc

This line:

.Shapes.Item(4).Fill.ForeColor.RGB= RGB(125,125,125)
Gives me an error: RGB(): Undefined function

I'm almost 100% sure the syntax is correct, but just in case, I was working off of this model:

http://msdn.microsoft.com/en-us/library/office/aa213151(v=office.11).aspx

Edited by Jewtus

Share this post


Link to post
Share on other sites

Put quotes around it?


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

The error message is correct:

RGB is neither a method of the PowerPoint object model nor a function of AutoIt. It is a VBA function.

So you have to write your own RGB method to mimic the VBA function.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Wouldn't  _WinAPI_RGB work?  I'm currently unable to test.  

 

Adam

Share this post


Link to post
Share on other sites

Put quotes around it?

 

I tried that and it didn't work... It gives a COM error (80020005) type mismatch

 

The error message is correct:

RGB is neither a method of the PowerPoint object model nor a function of AutoIt. It is a VBA function.

So you have to write your own RGB method to mimic the VBA function.

 

Not sure how I would actually do that...

Wouldn't  _WinAPI_RGB work?  I'm currently unable to test.  

 

Adam

I tried this and it doesn't give me any errors, however the shape that is created still has no fill, outline, or anything.

Share this post


Link to post
Share on other sites

What is the value of @error after

.Shapes.Item(5).Fill.ForeColor.RGB = ...

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

 

What is the value of @error after

.Shapes.Item(5).Fill.ForeColor.RGB = ...

Not sure exactly what you mean... I need to put something after the RGB. So if I put "RGB(125,125,125)" I get an error 80020005. If I don't put anything after it, I get a syntax error. If I remove the = sign I get no errors but obviously, the color doesn't change

Share this post


Link to post
Share on other sites

Put some number, for example 0xff0000.


♡♡♡

.

eMyvnE

Share this post


Link to post
Share on other sites

You said you tried the _WinAPI_RGB approach. What did you code?


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Put some number, for example 0xff0000.

Tried it

.Shapes.Item(5).Fill.ForeColor.RGB="0xff0000" gives me a type mismatch error

.Shapes.Item(5).Fill.ForeColor.RGB=0xff0000 doesn't do anything

You said you tried the _WinAPI_RGB approach. What did you code?

I tried this:

.Shapes.Item(5).Fill.ForeColor.RGB=_WinAPI_RGB(125,125,125)

Share this post


Link to post
Share on other sites

#19 ·  Posted (edited)

This script sets the background color of item 5 to a dark blue and writes @error = 0 to the SciTE console.

Tested with PP 2010.

$oPPT = ObjCreate("PowerPoint.Application")
If @error Then Exit MsgBox(0, "Error", "No PowerPoint available")
AddSlide(2, 11, "Example Project")
MsgBox(0, "Information", "Test ended.")
Func AddSlide($slideNum, $format, $projectName)
    $oPresentation = $oPPT.Presentations.Open(@ScriptDir & "\Test.potx")
    If @error Then Exit MsgBox(0, "Error", "Error opening potx")
    $rows = 10
    $cols = 3
    $oSlide1 = $oPresentation.Slides.Add($slideNum, $format)
    With $oSlide1
        .Shapes.Item(1).TextFrame.TextRange.Text = $projectName
        .Shapes.AddTextBox(1, 35, 60, 400, 50) ;type,left,top,width,height
        .Shapes.Item(2).TextFrame.TextRange.Text = "Overall Status"
        .Shapes.AddTextBox(1, 300, 60, 400, 50)
        .Shapes.Item(3).TextFrame.TextRange.Text = "Issues"
        .Shapes.AddTextBox(1, 500, 60, 400, 50)
        .Shapes.Item(4).TextFrame.TextRange.Text = "Next Week"
        .Shapes.AddShape(151, 30, 100, 200, 200)
        .Shapes.Item(6).Fill.ForeColor.RGB = 0xff0000 ; RGB(255, 0, 0)
        ConsoleWrite("@error = " & @error & @CRLF)
        .Shapes.AddTable($rows, $cols, 60, 120, 100, 100)
    EndWith
EndFunc   ;==>AddSlide
Edited by water
1 person likes this

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

.Shapes.Item(5).Fill.ForeColor.RGB = _WinAPI_RGB(255, 0, 0)

works fine here.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

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