Jump to content

MsoCommandBar management and UDF


Recommended Posts

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.

Link to comment
Share on other sites

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 (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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 (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

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 !

Link to comment
Share on other sites

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 (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

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:
Link to comment
Share on other sites

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 (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

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 !

Link to comment
Share on other sites

Which version of PowerPoint do you run?

I use PowerPoint 2010.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Glad to be of service :D

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...