Removing PowerPoint slide titles - vb.net

I need a piece of VB code that will remove all 'titles' from numerous PowerPoint slides. I am using a software to output SPSS data that has a unchangeable default setting to output title headings and I need these removed across 100 of slides. Any ideas?

With Andrew's pointer to the correct method, it's only a few minutes further to this (VBA, not VB.NET, but should be translate-able):
Sub DeleteTitles()
Dim oSl As Slide
For Each oSl In ActivePresentation.Slides
' Run this once with the IMMEDIATE window visible
' Verify that what YOU see as titles are actually what PPT sees as titles
Debug.Print oSl.SlideIndex & vbTab & oSl.Shapes.Title.TextFrame.TextRange.Text
' If all's well, comment out the Debug.Print line and uncomment this:
'oSl.Shapes.Title.Delete
Next
End Sub
Do note that what may look like a title to us isn't always a title as far as PPT is concerned. If you put PPT in Outline view, the title (as PPT sees it) will be next to the little slide icons. If there's nothing there, then there's no title and the code above won't work.

Related

How can I select all in Powerpoint VBA?

I have been struggling for a while to find a VBA code to select all the slides and all the shapes of a presentation (for some reason this seems to be of no one's interest). I have tried to set up a range with all the slides and then select all the shapes of the range, but that does not work. I also try looping slide by slide and accumulate the selection (msoFalse), but for that you also need to activate each slide and I was unable to do that.
I think selecting all the slides and shapes at once is useful to manipulate the fonts or run a full spell check. Your help would be really appreciated!!
Selecting objects in VBA is generally to be avoided. It's unreliable and slow. Instead, loop through every shape on every slide and perform whatever operation you need:
Sub DoStuffToShapes()
Dim oSlide as Slide
Dim oShape as Shape
For each oSlide in ActivePresentation.Slides
For each oShape in oSlide.Shapes
'Do stuff to the shape
Next oShape
Next oSlide
End Sub
If you've created a font theme and applied it to the Slide Master and Layouts, it's usually easier and faster to change fonts by modifying the theme and/or master rather than using VBA. VBA isn't needed for a spellcheck either.

Add clickable checkbox to powerpoint slide on Mac

I want to add a clickable checkbox (one or more) to a PowerPoint presentation slide. I'm using MacOS and Microsoft Office 365.
I guess that it is possible to do using macros created with VBA, but I have no idea what code needs to be created for this.
I would be very grateful if you would share the necessary code or suggest me another relevant ways to create clickable checkboxes in pptx under the Mac.
Checkboxes, labels, textboxes etc are all ActiveX features, and since ActiveX isn't supported on the Mac version of Office or in MacOS generally, you can't do this the way you would in Windows versions of Office.
You might be able to fake it by adding drawn rectangles and assigning a Run Macro action setting to each of them.
This page on the PPT FAQ that I maintain explains how to write the macro.
Determine which shape was clicked
https://www.pptfaq.com/FAQ00141_Determine_which_shape_was_clicked.htm
TL;DR - here's some sample code. This runs on both Windows and Mac (where bugs in PPT's VBA model force it to be more complicated than it would be otherwise):
Sub DoSomethingTo(oSh as Shape)
Dim oSl as Slide
Dim oShTemp as Shape
' oSh.Parent returns a valid reference to the shape's host slide:
Set oSl = ActivePresentation.Slides(oSh.Parent.SlideIndex)
' and oSh.Name works:
MsgBox oSh.Name
' So we use those two bits to get a reference
' to the clicked shape like so
Set oShTemp = oSl.Shapes(oSh.Name)
With oShTemp
.TextFrame.TextRange.Text = oSh.Name
' and whatever else you want to do with the shape
End With
End Sub

Is it possible to update only a selected linked object in PPT?

I'm trying to build a macro which will update only the selected linked object within a PowerPoint, but I cannot figure out how to do it.
The first part below is what I've used to update all linked objects, but I am currently dealing with massive Excel files, and presentations with 200+ linked objects, so one-at-a-time updating is the only way to go unfortunately.
The second part is what I was hoping would work.
First part:
Dim sld As Slide
Dim sh As Shape
For Each sld In ActivePresentation.Slides
For Each sh In sld.Shapes
If sh.Type = msoLinkedOLEObject Then
sh.LinkFormat.Update
End If
Next
Next
Second part:
With ActiveWindow.Selection
.LinkFormat.Update
EndWith
I'm pretty inexperienced with PPT VBA, so please bear with me. Is it possible to build something like this? (It's going to be part of a more complicated macro, so it ultimately will be more convenient than just Right Click + Update Link)
Give this a try:
Sub UpdateOLELink()
ActiveWindow.Selection.ShapeRange.LinkFormat.Update
End Sub

Adding comments to a powerpoint presentation using VBA

I want to add comments to a powerpoint presentation using VBA. I have this code using For loop but when I run the macro, the comment is adding to the whole presentation, i.e., all slides in the PPT. I wanted to add the comment to a selected slide. Can anyone help?
This is the code using For loop to add some comment:
Sub FictiousNames()
Dim mySlides As Slide
Dim cmtNew As Comment
For Each mySlides In ActivePresentation.Slides
Set cmtNew = mySlides.Comments.Add(Left:=12, Top:=12, _
Author:="Fictious Names", AuthorInitials:="", _
Text:="Please verify if this is an approved fictitious name. Also, you can use the following link to generate fictitious names: https://microsoft.sharepoint.com/sites/LCAWeb/Home/Copyrights-Trademarks-and-Patents/Trademarks/Fictitious-Names-Finder)"
Next mySlides
End Sub
If you want to add a comment to a single (certain) slide, you don't need to use the For loop, just copy the code below:
Sub FictiousNames()
' modify the number in brackets (9) to your slide number
ActivePresentation.Slides(9).Comments.Add 12, 12, "Fictious Names", "", _
"Please verify if this is an approved fictitious name. Also, you can use the following link to generate fictitious names: https://microsoft.sharepoint.com/sites/LCAWeb/Home/Copyrights-Trademarks-and-Patents/Trademarks/Fictitious-Names-Finder)"
End Sub

Error in script which copies charts from Excel to PowerPoint

I am attempting to call the below Sub in order to copy given chart to a specified PowerPoint presentation. However, when I run the macro which calls this Sub, the line indicated below returns the following error: "Object doesn't support this property or method." What's odd is that both Shapes and Slide do contain the methods which are called. As well, the bitmap is correctly copied to my clipboard and pastes into the slide before the error is called. You will find the Sub() below.
Sub copyChart(chrt As Chart, pres As PowerPoint.Presentation)
Dim curSlide As Slide, dummySlide As Slide
Set dummySlide= pres.Slides(2) 'Second slide is dummy slide.
Set curSlide = dummySlide.Duplicate(1) 'Duplicate dummy, set as current slide.
chrt.CopyPicture Appearance:=xlScreen, Format:=xlBitmap 'Copy the chart as a picture.
curSlide.Shapes.Paste '<-----------Error here.
End Sub
As well, I was hoping to provide a .txt file of my entire script, but was unsure how (it is a little lengthy to paste here). Thanks for your help.
(Note that this implementation is very similar to that at Paste Excel Chart into Powerpoint using VBA, further confusing me.)
I have had a lot of trouble in recent versions of Office. 2003 and earlier didn't have this problem, 2007 and 2010 had it a bit, and 2013 and 2016 have it in spades.
When you step through the code it works fine, but when you run it at full speed, it errors on the paste.
It's as if the copy doesn't have time to finish finish, so when you paste the clipboard doesn't have anything in it yet to paste.
Sometimes this helps:
chrt.CopyPicture Appearance:=xlScreen, Format:=xlBitmap
DoEvents
curSlide.Shapes.Paste
DoEvents tells VBA to wait while background operations have a chance to finish up.
It looks like the error can be attributed to how VBA handles variables across different references. (In particular, how PPT VBA handles them.) I was able to get the macro to work by actively selecting/copying the charts. I will need to do a little more research to get why variables cause problems, but at least I know how tackle the problem.
Sub copyChart(curSlide As Slide)
Dim chr as ChartObject
Set chr = Sheets("CHARTSHEET").ChartObjects(1)
Sheets("CHARTSHEET").Select
ActiveChart.CopyPicture
curSlide.Shapes.PasteSpecial
End Sub
I like to use another method, I like to define an Object, then set it to the pasted Chart. Afterwards, it's much easier modifying the pasted Chart object's parameters inside PowerPoint (from Excel).
See code below:
Sub copyChart(curSlide As Slide)
Dim chr As ChartObject
Dim myChart As Object
Set chr = Sheets("CHARTSHEET").ChartObjects(1)
chr.Copy
' setting myChart object to the pasted chart (let's me later an easy way to modify it's parameters)
Set myChart = curSlide.Shapes.PasteSpecial(ppPasteBitmap, msoFalse) ' can change first parameter to other avaialabe formats : ppPasteGIF, ppPasteEnhancedMetafile, ppPasteOLEObject, etc.
' set different parameters for the pasted chart in PowerPoint slide
With myChart
.Left = 200
.Top = 200
End With
End Sub
In the code line:
Set myChart = curSlide.Shapes.PasteSpecial(ppPasteBitmap, msoFalse)
You can change the first parameter in brackets: ppPasteBitmap to many other avaialble formats (test them and see which one gives you the best result), such as: ppPasteGIF, ppPasteEnhancedMetafile, ppPasteOLEObject, etc.