How to start slideshow in PowerPoint using com32 - com

I am trying to control my PowerPoint presentation using python via com.
There is an article on how to do this here and it suggest I do the following:
app = win32com.client.Dispatch("PowerPoint.Application")
objCOM = app.Presentations.Open(FileName="path_to_file", WithWindow=1)
objCOM.SlideShowWindow.View.Next()
If I do this, I get the error
(-2147352567, 'Ausnahmefehler aufgetreten.', (0, 'Microsoft PowerPoint', 'Presentation.SlideShowWindow : Invalid request. There is currently no slide show view for this presentation.', '', 0, -2147188160), None)
On the last line. It seems, that Open does not start the slide show.
I have been looking through the documentation of the PowerPoint object model here, but was unable to find a way to start the slide show of a presentation.
Any suggestions on how to do this?

Call SlideShowSettings.Run() after opening the file:
import win32com.client as win32
app = win32.Dispatch("PowerPoint.Application")
objCOM = app.Presentations.Open(FileName="path_to_file", WithWindow=1)
#START THE SLIDESHOW
objCOM.SlideShowSettings.Run()
objCOM.SlideShowWindow.View.Next()

Related

How to program a PowerPoint custom object like Thinkcell objects?

I am very new to PowerPoint add-on development so please bear with me.
There are many objects that can be inserted into a PowerPoint slide, such as text box, shape, chart, etc. Is there a way to build my own custom object with custom properties and functionalities? For example, with the Thinkcell add-on, you can insert a Thinkcell chart object, connect it to Excel workbook, edit it, and show it. To the best of my understanding, this is a kind of custom object built into the Thinkcell add-on.
How can I build a custom object like this?
I have checked some tutorials on building a PowerPoint add-on with VBA, VSTO, and Javascript. To the best of my understanding, these technologies allow users to build some user interfaces to interact and modify the PowerPoint slides, such as creating and modifying elements in the slides. However, I don't see examples of creating a custom object using these technologies. Thus I am very curious about how add-ons create their custom element.
Thanks!
First, you will need to install the necessary npm packages and set up the development environment.
For example, you can use the following command to install the Office.js library:
npm install #microsoft/office-js
Then, you can use the following code to create a custom object in a PowerPoint add-in:
Office.initialize = function () {
// Create a new shape on the active slide
var shape = PowerPoint.createShape("MyCustomObject", Office.MsoAutoShapeType.msoShapeRectangle, 50, 50, 100, 100);
// Add a custom property to the shape
shape.customProperties.add("dataSource", "Excel workbook");
// Define a function to be called when the user clicks on the shape
shape.click = function () {
// Open the Excel workbook and display the data
Office.context.ui.displayDialogAsync("https://example.com/excel-workbook", {height: 50, width: 50});
};
};
Here is how you might accomplish this using VBA:
Sub ChangeObjectColor()
Dim obj As Shape
' Get a reference to the custom object
Set obj = ActivePresentation.Slides(1).Shapes("MyObject")
' Check the value of the FillColor property
If obj.FillColor = "red" Then
' Set the fill color of the object to red
obj.Fill.ForeColor.RGB = RGB(255, 0, 0)
ElseIf obj.FillColor = "green" Then
' Set the fill color of the object to green
obj.Fill.ForeColor.RGB = RGB(0, 255, 0)
End If
End Sub

Display a files icon in a PictureBox

I know there is a lot of these noob questions already.
I wrote a small code for display the Icon from a file in a PictureBox and its not working :|
Button6.BackgroundImage = Bitmap.FromHicon(
New Icon(OpenFileDialog1.FileName, New Size(48, 48)).Handle
)
The error says:
Argument 'picture' must be a picture that can be used as a Icon
If anyone know whats the problem, please write it down.
This error means that the file you are trying to open is not an icon. An icon file has extension .ico. Also you need to open the OpenFileDialog1 before geting the selected file name:
If OpenFileDialog1.ShowDialog = DialogResult.OK Then
Button1.BackgroundImage = Bitmap.FromHicon(New Icon(OpenFileDialog1.FileName, New Size(48, 48)).Handle)
End If

Positioning of a menu item image (hbmpItem of a MENUITEMINFO) in a context menu

I am inserting a menu item into an Outlook Context menu for a subject text control. Here you can find a previous question I had on doing this.
The issue I have is that the image of the menu item is positioned strangely in Outlook 2010. In Outlook 2007 it is positioned differently. It seems that the menu item is holding the position for the checked image free in Outlook 2010.
This shows how my menu item looks with the below code. Notice the large space to the left of the image.
This shows how it looks when i add the MIIM_CHECKMARKS flag to fMask and a bitmap to the hbmpUnchecked pointer.
Dim bmp As Drawing.Bitmap = My.Resources.olContextMenuIcon
bmp.MakeTransparent(bmp.GetPixel(10, 10))
hbitmap = bmp.GetHbitmap
Dim mii As New NativeMethodsEX.MENUITEMINFO
With mii
.cbSize = Marshal.SizeOf(mii)
.fMask = NativeMethodsEX.MIIM.MIIM_BITMAP Or NativeMethodsEX.MIIM.MIIM_STRING Or NativeMethodsEX.MIIM.MIIM_FTYPE Or NativeMethodsEX.MIIM.MIIM_STATE Or NativeMethodsEX.MIIM.MIIM_ID
.wID = WM_APP
.fType = NativeMethodsEX.MFT.MFT_STRING
.dwTypeData = String.Concat("Wrong Position")
.fState = NativeMethodsEX.MFS.MFS_ENABLED
.hbmpItem = hbitmap
End With
If ShowTop Then
NativeMethodsEX.InsertMenuItem(aHwnd, 0, True, mii)
NativeMethodsEX.InsertMenu(aHwnd, 1, NativeMethodsEX.MFT.MFT_BYPOSITION Or NativeMethodsEX.MFT.MFT_SEPARATOR, Nothing, Nothing)
Else
Dim menuItemCount As Integer = NativeMethodsEX.GetMenuItemCount(aHwnd)
NativeMethodsEX.InsertMenu(aHwnd, menuItemCount, NativeMethodsEX.MFT.MFT_BYPOSITION Or NativeMethodsEX.MFT.MFT_SEPARATOR, Nothing, Nothing)
NativeMethodsEX.InsertMenuItem(aHwnd, menuItemCount + 1, True, mii)
End If
NativeMethodsEX.DrawMenuBar(subjectRegionHwnd)
So how can I tell the menu item not to reserve the space for the check / uncheck image?
I have two answers to this problem.
I indicated above that the issue existed on an menu in Outlook 2010 but not in Outlook 2007. This is not true. These office versions are of course on different computers and it was a display setting in windows that was the cause of the problem. The above menu is what you get when you have the setting "Use Visual Styles on Windows and buttons" in Performance Options > Visual Effects turned off (Win 7). If you enable this setting then the menus look and especially act very differently.
But what if a user disables this setting how can you deal with it (Not sure if this is relevant for Win10).
You need to set the menu style through the use of the Menuinfo in particular you need to set the flag MNS_NOCHECK. Then the space is gone as the menu no longer is expecting the check marks.
This solution can also be seen here in another stackoverflow answer.

Add Image to Custom Task Pane Title in Outlook - VB.Net

I have created a custom task pane in VB.Net for Outlook using the Code given below and I would like to add more content to the header (image and a button) of the User Control instead of just the title. Is there a way I can achieve this?
myUserControl1 = New OutlookTaskPane
myUserControl1.TabStop = True
Dim width As Integer = myUserControl1.Width
myCustomTaskPane = Me.CustomTaskPanes.Add(myUserControl1, "My Custom Task Pane")
myCustomTaskPane.Width = width
myCustomTaskPane.Visible = True
myCustomTaskPane.DockPositionRestrict = Microsoft.Office.Core.MsoCTPDockPositionRestrict.msoCTPDockPositionRestrictNoChange
Let me know if there is any other way of achieving this please.
Thanks.
Unfortunately the TaskPane header is not customizable. Only Add-in Express supports similar customizations using their implementation of Advanced Form Regions (although only the header icon and header color can be changed and you can't add Windows Forms controls to it). Another option is to implement your own type of Task Pane so you have complete control over the UI; see https://code.msdn.microsoft.com/OlAdjacentWindows/.

VBScript and VBA - namespace issues

I want to automate some steps using VBA, and I also want to be able to execute everything from the command line. In my example I'm using Corel Draw, but I think that my question is independent from Corel Draw - its more a question about namespaces.
So I wrote the following small script (called foo.vbs):
dim drawApp
Set drawApp = CreateObject( "CorelDraw.Application.14" )
drawApp.OpenDocument( "C:\foo\bar.cdr" )
Dim exportFilter
set exportFilter = drawApp.ActiveDocument.ExportBitmap("bar.png", cdrPNG, cdrAllPages, cdrRGBColorImage, 10206, 8578, 300, 300, cdrNormalAntiAliasing, False, False, True, False, cdrCompressionNone)
Then, I run it from the command line:
cscript.exe foo.vbs
I get the error that cdrPNG is not defined. Of course - I did not include any Corel Draw specific stuff into the VBScript. But how do I incluce VBA stuff that is specific for one application? (This might also enable me to write dim drawApp as CorelDRAW.Application or something like that).
I'm very new to VBA and VBScripts and I have not been able to find good tutorials or reference resources (the Microsoft site is not very helpful). Any pointers welcome.
EDIT:
I copied the ExportBitmap-part from the code that was generated when I recored a macro in Corel Draw. Studying code from recored macros seems a nice way to get to know the VBA capabilities of the software. Is there a better way?
If you considered to use a .wsf script package instead .vbs script file, everything would be easier for you. Adding type libraries supported in WSF files.
<package>
<job id="Main">
<!--
add type library reference specifying progid and version
then all enum constants will be ready to use
-->
<reference object="CorelDraw.Application" version="14.0" />
<script language="VBScript">
Option Explicit
Dim drawApp
Set drawApp = CreateObject("CorelDraw.Application.14")
drawApp.OpenDocument("C:\foo\bar.cdr")
Dim exportFilter
Set exportFilter = drawApp.ActiveDocument.ExportBitmap( _
"C:\foo\bar.png", cdrPNG, cdrAllPages, cdrRGBColorImage, 10206, 8578, 300, 300, _
cdrNormalAntiAliasing, False, False, True, False, cdrCompressionNone, Nothing, Nothing)
exportFilter.Finish
drawApp.Quit
</script>
</job>
</package>