Jump to content
Sign in to follow this  
Eazyrider

MsoCommandBar management and UDF

Recommended Posts

Eazyrider

Hi everybody,

I'm having trouble to manage the control with ClassNameNN MsoCommandBar5 of a PowerPoint application. This control corresponds to the Menubar of PowerPoint. In short, I just want to use the command paste, without using the keystroke "^v".

I have found a way of doing that in a manner that is not very satisfying because it is striclty equivalent to sending "^v" using the following command lines :

$hPPT = WinGetHandle ("")
ControlSend($hPPT, "", "MsoCommandBar5", "Eo") ; I'm using a french version of PPT. "Eo" corresponds to "&Edition/C&oller" which means Edit/Paste

Does anyone know how to handle the different menu items of this MsoCommandBar ? Is there any UDF existing on this particular control by chance ?

Thanks in advance for your answers.

Share this post


Link to post
Share on other sites
water

Welcome to AutoIt and the forum!

Why use the control to paste some content to PowerPoint?

PowerPoint has a COM interface so it should be easy to paste the content to a presentation.

Can you elaborate on what you exactly want to do?

Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
Eazyrider

Hey water,

Thanks for quick answer :)

Actually, I'm simply automating a Copy Paste of a picture on a slide that is managed with an old version of Paint Shop Pro software. I would also like to play with the properties of the picture I have just Paste on my slide.

Edited by Eazyrider

Share this post


Link to post
Share on other sites
water

Here is the to the PowerPoint UDF (User Defined Functions). It could be a starting point to do what you want.

Where do you want to position the pasted picture?

Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
Eazyrider

I'm actually reading stuff in the help menu about the COM. Since I'm a beginner, I didn't even know the existance of that :idiot:. Looks very powerful.

To be precise, I want to resize the picture by setting the height and reposition it at the Horizontal location 2.16cm and Vertical 2.32cm.

Thanks again for your help water !

Share this post


Link to post
Share on other sites
water

Small example script (reduced to the max) to create a new PPT presentation, add a slide and paste the PNG file to the slide, reposition it and reduce width and height by 50%.

if you have a JPG in your clipboard replace $ppPastePNG with $ppPasteJPG.

$oPPT_Error = ObjEvent("AutoIt.Error", "PowerPoint_ErrorHandler")

Global Const $PPLAYOUTTEXT = 2
Global Const $ppPasteBitmap = 1
Global Const $ppPasteDefault = 0
Global Const $ppPasteEnhancedMetafile = 2
Global Const $ppPasteGIF = 4
Global Const $ppPasteHTML = 8
Global Const $ppPasteJPG = 5
Global Const $ppPasteMetafilePicture = 3
Global Const $ppPasteOLEObject = 10
Global Const $ppPastePNG = 6
Global Const $ppPasteRTF = 9
Global Const $ppPasteShape = 11
Global Const $ppPasteText = 7
; Open PPT
Global $oAppl = ObjCreate("PowerPoint.Application")
If @error Or Not IsObj($oAppl) Then Exit MsgBox(0, "Error", "Error creating PPT application. @error = " & @error & ", @extended = " & @extended)
$oAppl.Visible = True
; Get presentation interface
$oPresInterface = $oAppl.Presentations
; Add Presentation
Global $oPresentation = $oPresInterface.Add(True)
; Create a new slide with text layout, index = 1
Global $oSlide1 = $oPresentation.Slides.Add(1, $PPLAYOUTTEXT)
; Paste the picture
$oRange = $oPresentation.Slides(1).Shapes.PasteSpecial($ppPastePNG)
If @error Or Not IsObj($oRange) Then Exit MsgBox(0, "Error", "Clipboard is empty or contains invalid data type. @error = " & @error & ", @extended = " & @extended)
; Position the picture
MsgBox(0, "", "...")
$oRange.left = 100
$oRange.Top = 150
MsgBox(0, "", "...")
$oRange.Height = $oRange.Height/2
$oRange.Width = $oRange.Width/2
MsgBox(0, "", "...")
; Close PPT
$oAppl.Quit()

Func PowerPoint_ErrorHandler()

Local $bHexNumber = Hex($oPPT_Error.number, 8)
Local $sError = "COM Error Encountered in " & @ScriptName & @CRLF & _
"@AutoItVersion = " & @AutoItVersion & @CRLF & _
"@AutoItX64 = " & @AutoItX64 & @CRLF & _
"@Compiled = " & @Compiled & @CRLF & _
"@OSArch = " & @OSArch & @CRLF & _
"@OSVersion = " & @OSVersion & @CRLF & _
"Scriptline = " & $oPPT_Error.scriptline & @CRLF & _
"NumberHex = " & $bHexNumber & @CRLF & _
"Number = " & $oPPT_Error.number & @CRLF & _
"WinDescription = " & StringStripWS($oPPT_Error.WinDescription, 2) & @CRLF & _
"Description = " & StringStripWS($oPPT_Error.description, 2) & @CRLF & _
"Source = " & $oPPT_Error.Source & @CRLF & _
"HelpFile = " & $oPPT_Error.HelpFile & @CRLF & _
"HelpContext = " & $oPPT_Error.HelpContext & @CRLF & _
"LastDllError = " & $oPPT_Error.LastDllError
MsgBox(64, "Debug Info", $sError)
EndFunc ;==>PowerPoint_ErrorHandler

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
Eazyrider

Very nice Water ! Thanks alot :thumbsup:.

I just replaced PNG by Default to make it work.

Now I have a very minor problem : I noticed that straight after the creation of the object,

Global $oAppl = ObjCreate("PowerPoint.Application")
the clipboard gets empty... I don't see any reason why... though it's not a big problem in my application since I can copy paste after I create the ppt file. It's just to understand things... :graduated:

Share this post


Link to post
Share on other sites
water

Seems to be a problem with $ppPasteDefault. As soon as a I use $ppPastePNG or $ppPasteJPG it works just fine.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
Eazyrider

Oddly, it behaves in a different way on my comp : when PowerPoint is already open, if I launch your program as you wrote it (just changing $ppPastePNG with $ppPasteDefault), it works fine, the clipboard doesn't get empty and the picture is correctly pasted. Now if the PowerPoint application is closed and that Autoit generates a new one with the command ObjCreate, I can see that the clipboard is now empty... anyway it is not that terrible, just weird... and somehow disturbing :huh:

PS: I think this is my last post available for today... I will keep you inform tomorrow Water of the evolution tomorrow. Thanks again for your time !

Share this post


Link to post
Share on other sites
water

Which version of PowerPoint do you run?

I use PowerPoint 2010.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
Eazyrider

To finish off this conversation : I use a 2003 version of PPT. That might explain the differences of behaviour !

Finally, I was able to build my application properly using COM as described in your example.

Thanks again for your help Water !

Share this post


Link to post
Share on other sites
water

Glad to be of service :D


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
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  

×