How can I select all in Powerpoint VBA? - 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.

Related

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

Removing PowerPoint slide titles

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.

VBA: delete borders from floating images in ms-Word

I have this code to put a border on all images in my Word document. Inline shapes as floating shapes. Works fine. All images have a border. But my images on the first page (like Logo) also have a border.
Can anyone help me out with code for deleting the borders around floating images on the front page? Or specific shapes?
Thank you.
Kem
The Selection.Information(wdActivePageEnd) command can give you the current page number and in your case all you need to do is set the current selection point or working range to the top of the document ... and now you know you are on page 1.
The second challenge is selecting or setting a working range to only the first page. I use the built-in Bookmark "\Page".
The third challenge is identifying the type of shape and for that you use the Shape.Type property. If you are going after images remember they could be embedded or linked so you have to use the two property types.
Finally, in your questions you are asking how to remove borders. Well IMO you don't have to remove them, you only hide them.
Here is example code that you can study and figure out how to integrate with your existing code.
Sub RemoveBorders()
Dim rng As Word.Range, shp As Word.Shape
Set rng = ActiveDocument.Content
rng.Collapse Word.WdCollapseDirection.wdCollapseStart
Set rng = ActiveDocument.Bookmarks("\Page").Range
For Each shp In rng.ShapeRange
If shp.Type = msoPicture Or shp.Type = msoLinkedPicture Then
shp.Line.Visible = False
End If
Next
End Sub

VBA code to auto update PowerPoint links to Word

I have hundreds of PowerPoint presentations that all have linked Word objects in them. How can I auto-update all of the links without opening each presentation? I'm assuming it'll be done with VBA, but the only VBA examples I can find are for auto-updating linked Excel objects. I'm not familiar enough with VBA to modify the code.
Ultimately, I'd like to run this via Command Prompt.
Using PowerPoint & Word 2013.
DragonSamu's right ... but to get you started, try this from within PPT itself, then work out how to rewrite it in a scripting language or something that will compile to an EXE
For each file you want to process, open the file (via code) then
Call UpdateLinks(ActivePresentation)
Sub UpdateLinks(oPres As Presentation)
Dim oSl As Slide
Dim oSh As Shape
For Each oSl In oPres.Slides
For Each oSh In oSl.Shapes
If oSh.Type = msoLinkedOLEObject Then
oSh.LinkFormat.Update
End If
Next
Next
End Sub

Need to set shape position in PowerPoint to the same value across all slides

I have dozens of PowerPoint shows that contain dozens of slides each. They are very basic in that there is only one shape on each slide and there is no animation being used on the shape or between slides. The issue is that the person who created them didn't really pay attention to the vertical position of the shapes from slide to slide so it's very noticeable when going from one slide to the next.
I would like to be able to quickly set the vertical position to the same value for each shape on each slide. The horizontal position is fine. I've been doing them manually but there are a lot of slides and slide shows to go through and I'd rather not have to do this as it is very time consuming.
I've done some searching here on this site as well as on Google but haven't found anything yet. If it requires VBA code, that's fine too.
I am using PowerPoint 2010.
As a starting point (total air code, mind you):
Sub LineEmUpDano()
Dim oSl as Slide
Dim sngTop as Single
' Pick up the top position of the first shape
' on the first slide:
SngTop = ActivePresentation.Slides(1).Shapes(1).Top
' Apply the top position to each slide in the pres
For Each oSl in ActivePresentation.Slides
oSl.Shapes(1).Top = sngTop
' you could instead use
' oSl.Shapes(1).Top = 42 ' or whatever value you like
' Values are in points, 72 points to the inch
Next ' slide
End Sub
Using Steve's suggestion above as a jumping off point and then reading some tutorials I was able to come up with a working script:
Sub UniformHeight()
Dim SlideToCheck As Slide
Dim ShapeIndex As Integer
For Each SlideToCheck In ActivePresentation.Slides
For ShapeIndex = SlideToCheck.Shapes.Count To 1 Step -1
SlideToCheck.Shapes(ShapeIndex).Top = 36
Next
Next
End Sub