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
Related
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()
I am trying to create a new instance of Excel using VBA using:
Set XlApp = New Excel.Application
The problem is that this new instance of Excel doesn't load all the addins that load when I open Excel normally...Is there anything in the Excel Application object for loading in all the user-specified addins?
I'm not trying to load a specific add-in, but rather make the new Excel application behave as though the user opened it themself, so I'm really looking for a list of all the user-selected add-ins that usually load when opening Excel.
I looked into this problem again, and the Application.Addins collection seems to have all the addins listed in the Tools->Addins menu, with a boolean value stating whether or not an addin is installed. So what seems to work for me now is to loop through all addins and if .Installed = true then I set .Installed to False and back to True, and that seems to properly load my addins.
Function ReloadXLAddins(TheXLApp As Excel.Application) As Boolean
Dim CurrAddin As Excel.AddIn
For Each CurrAddin In TheXLApp.AddIns
If CurrAddin.Installed Then
CurrAddin.Installed = False
CurrAddin.Installed = True
End If
Next CurrAddin
End Function
Using CreateObject("Excel.Application") would have the same result as using New Excel.Application, unfortunately.
You will have to load the Addins that you need individually by file path & name using the Application.Addins.Add(string fileName) method.
I'm leaving this answer here for anyone else who ran into this problem, but using JavaScript.
A little background... In my company we have a 3rd party web app that used JavaScript to launch Excel and generate a spreadsheet on the fly. We also have an Excel add-in that overrides the behavior of the Save button. The add-in gives you the option of saving the file locally or in our online document management system.
After we upgraded to Windows 7 and Office 2010, we noticed a problem with our spreadsheet-generating web app. When JavaScript generated a spreadsheet in Excel, suddenly the Save button no longer worked. You would click save and nothing happened.
Using the other answers here I was able to construct a solution in JavaScript. Essentially we would create the Excel Application object in memory, then reload a specific add-in to get our save button behavior back. Here's a simplified version of our fix:
function GenerateSpreadsheet()
{
var ExcelApp = getExcel();
if (ExcelApp == null){ return; }
reloadAddIn(ExcelApp);
ExcelApp.WorkBooks.Add;
ExcelApp.Visible = true;
sheet = ExcelApp.ActiveSheet;
var now = new Date();
ExcelApp.Cells(1,1).value = 'This is an auto-generated spreadsheet, created using Javascript and ActiveX in Internet Explorer';
ExcelApp.ActiveSheet.Columns("A:IV").EntireColumn.AutoFit;
ExcelApp.ActiveSheet.Rows("1:65536").EntireRow.AutoFit;
ExcelApp.ActiveSheet.Range("A1").Select;
ExcelApp = null;
}
function getExcel() {
try {
return new ActiveXObject("Excel.Application");
} catch(e) {
alert("Unable to open Excel. Please check your security settings.");
return null;
}
}
function reloadAddIn(ExcelApp) {
// Fixes problem with save button not working in Excel,
// by reloading the add-in responsible for the custom save button behavior
try {
ExcelApp.AddIns2.Item("AddInName").Installed = false;
ExcelApp.AddIns2.Item("AddInName").Installed = true;
} catch (e) { }
}
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/.
I am designing an application and had to instantiate controls via code. The problem is that I am unable to change the background color. I tried to look all over the internet, but no succes. I have contacted the Microsoft support service, but no succes either.
I read that you normally change a color by using System.Color or System.ColorHelper. Both are not accesible in the application.
So how to solve the following problem:
TextBox^ txtID = ref new TextBox();
txtID->Background = ?;
I have the solution, first make a brush object and set the color and assign that color to your controls background. I used the following:
SolidColorBrush^ myBrush = ref new SolidColorBrush(Windows::UI::Colors::Red);
TextBox^ txtID = ref new TextBox();
txtID->Background = myBrush;
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>