VBA Code: Change Embedded Videos to Linked?

Created: Friday, November 16, 2012, posted by at 4:15 am


No Longer Working?

This code no longer works in PowerPoint and is retained for archival reasons.

Have you created a huge monster PowerPoint file that’s hundreds of megabytes in size or even a gigabyte? The culprit may be any videos you have inserted on your slides! In years gone by, we always recommended that users place their videos (or any other media or linked files) in the same folder as their PowerPoint presentations so that the links to video files worked when you moved the presentation to another computer. You could then just copy the entire folder to another computer!

VBA Code: Change Embedded Videos to Linked?

PowerPoint 2010 changed everything! Rather than linking videos, the default option was now to embed the videos as part of your PowerPoint file. And that’s how it has been for subsequent releases of PowerPoint, including versions 2011 and 2016 on Mac, and versions 2013 and 2016 on Windows.

Undeniably, this had its share of advantages: there are no more missing videos, and you no longer need to create a folder to manage all your media files. Yes, that’s less housekeeping for you to do, but housekeeping does have its own share of benefits. For one, you don’t end up with huge monster files!

Ideally, you can just delete all the video files and then insert them again. This time, you can opt to link files rather than embedding them. To do that, click the down arrow next to the Insert button, and you’ll find an option to link rather than embed. Yes, we know that’s not too obvious!

Link, rather than insert media files

But what if you did not want to re-insert videos all over again? Then just copy all the videos to the same folder as your PowerPoint file, and then run this EmbeddedMoviesToLinkedMovies VBA snippet, graciously coded by Steve Rindsberg of PowerPoint FAQ. Thanks to Steve for allowing us to reproduce this code here. Steve adds that it’s best that you do this only with a copy of your original file.

First you need to know how you can run VBA scripts in PowerPoint. Then use this code. Explore the code a bit though since Steve has put in some helpful comments so that you can edit some values as required. Most importantly, be sure to edit the path as directed in the comments, else this code won’t work.

You can actually create a blank, new presentation and insert this code into the VBA editor. To learn how you bring up the VBA editor and add code, look at our VBA scripts in PowerPoint tutorial. Yes, it’s not necessary that this code is placed in the same presentation as your embedded videos; all you need to do is make sure that both presentations (the presentation with this code, and the presentation with the video clips) are open at the same time.

Sub EmbeddedMoviesToLinkedMovies()
Dim oSl As Slide
Dim oSh As Shape
Dim x As Long
Dim sPath As String
 
' Edit this to the path where vids are stored,
' path must end in backslash
sPath = "C:StuffMovieStuffThisProjectsMovieStuff"
 
For Each oSl In ActivePresentation.Slides
    For x = oSl.Shapes.Count To 1 Step -1
        Set oSh = oSl.Shapes(x)
        If oSh.Type = msoMedia Then
            If oSh.MediaType = ppMediaTypeMovie Then
                If oSh.MediaFormat.IsEmbedded Then
                    Debug.Print oSh.Name
                    Call ConvertToLinked(oSh, sPath)
                End If
            End If
        End If
    Next    ' Shape
Next    ' Slide
 
End Sub
 
Sub ConvertToLinked(oSh As Shape, sPath As String)
 
Dim oSl As Slide
Dim oNewVid As Shape
Dim x As Long
Dim lZOrder As Long
 
Set oSl = oSh.Parent
lZOrder = oSh.ZOrderPosition
 
Set oNewVid = oSl.Shapes.AddMediaObject2(sPath & oSh.Name, msoTrue, msoFalse, _
    oSh.Left, oSh.Top, oSh.Width, oSh.Height)
 
Do Until oNewVid.ZOrderPosition = lZOrder
    oNewVid.ZOrder (msoSendBackward)
Loop
 
oSh.Delete
End Sub

Once you have placed this code in the VBA editor, close the window to get back to your PowerPoint window. Before you proceed further, it’s a great idea to save your file — be sure to save as a PowerPoint Macro-Enabled Presentation with the PPTM file extension. If you save as any of the other file formats, PowerPoint will offer to remove the macros, and then, of course, the code to change embedded videos to linked will not work! See our PowerPoint File Formats page to learn about these file formats.

Then open or switch to the presentation with the embedded videos and run the macro. To do so, press the Alt + F8 shortcut key. In the Macro dialog box that appears, next to Macro in: choose All open presentations, as shown in the figure below. Click the EmbeddedMoviesToLinkedMovies Macro name, and then click the Run button.

Look for a macro in all open presentations

Thank you so much, Steve.

We tested this code using PowerPoint 2010 for Windows. Also, we have not checked this on PowerPoint 2011 for Mac. If you do, and it does work or not, then we request you leave a comment below this post and share your thoughts. Of course, you should share your thoughts even if you are a Windows user.


Steve RindsbergSteve Rindsberg has been associated with PowerPoint since the product originated more than two decades ago. His PowerPoint FAQ site is a treasure trove of PowerPoint information.

When he’s not updating his site, he’s working on his popular PPTools add-ins for PowerPoint. Steve’s also into a lot of print technology-related stuff.

You May Also Like: Use VBA in PowerPoint, Even if You Can’t Program for Nuts | Create Spirographs in PowerPoint Programmatically | Resources on PowerPoint Programming and VBA


The views and opinions expressed in this blog post or content are those of the authors or the interviewees and do not necessarily reflect the official policy or position of any other agency, organization, employer, or company.



Related Posts


Filed Under: Programming
Tagged as: , , , ,

1 Comment

One response to “VBA Code: Change Embedded Videos to Linked?”

  1. […] November 16, 2012 – VBA Code: Change Embedded Videos to Linked? […]

Microsoft and the Office logo are trademarks or registered trademarks of Microsoft Corporation in the United States and/or other countries.

Plagiarism will be detected by Copyscape

© 2000-2024, Geetesh Bajaj - All rights reserved.

since November 02, 2000



-->