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

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

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.

How can I delete all transitions in MS Powerpoint with VBA?

We prepare hundreds of Powerpoint documents per week for use with screen-reading software and need to remove all animations and transitions from each one. I'd like to write a Powerpoint add-in that automatically does this when the file is loaded. I've figured out how to delete all animations using the following code in an auto_open() sub which I've imported as an add-in:
'Loop Through Each Slide in ActivePresentation
For Each sld In ActivePresentation.Slides
'Loop through each animation on slide
For x = sld.TimeLine.MainSequence.Count To 1 Step -1
'Remove Each Animation
sld.TimeLine.MainSequence.Item(x).Delete
Next x
Next sld
However, I'm not sure how to delete transitions with this method. I've essentially solved the problem visually by adding in this line,
sld.SlideShowTransition.Duration = 0
but I'd like to outright delete the transitions as they interfere with clients' screen-reading software. Deleting the object in the paradigmatic VBA way (SlideShowTransition.Delete) doesn't work.
Any ideas?
Thanks in advance.
This'll do it:
sld.SlideShowTransition.EntryEffect=0

VBA - Ungroup a Table in PowerPoint

I am looking for an automated way to ungroup a table in power point to create shapes.
I found the following tutorial:
Tutorial
Further, I wanted to record the macro(I am quite new to vba), however in power point 2010 the macro recorder is not available any more. Any suggestions, how to create the above tutorial in vba?
I appreciate your replies!
Here's an example to get you started. Be sure to select the table you want to work with first.
Sub PasteAndUngroup()
Dim oSh As Shape
Dim oSl As Slide
Set oSh = ActiveWindow.Selection.ShapeRange(1)
Set oSl = oSh.Parent
oSh.Copy
Set oSh = oSl.Shapes.PasteSpecial(ppPasteEnhancedMetafile)(1)
oSh.Ungroup
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.

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