This is the print version of this page. All content is copyright Indezine.com 2000- .



PowerPoint Programming: November 2012

Everything about PowerPoint programming including VBA, VSTO, and more.

See Also:
PowerPoint and Presenting Blog
PowerPoint and Presenting Glossary
PowerPoint and Presenting Tutorials

Subscribe to this blog



VBA Code: Change Embedded Videos to Linked?

Friday, November 16, 2012
posted by Geetesh on Friday, November 16, 2012 IST

PowerPoint Random Number GeneratorHave 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, I 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!

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 version 2011 on Mac, and version 2013 on Windows.

Undeniably, this had its share of advantages -- no more missing videos, and you no longer need to create a folder. 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, I know that's not too obvious!


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 within 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:\Stuff\MovieStuff\ThisProjectsMovieStuff\"

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 that, 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.



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.

Labels: , , , ,





comments powered by Disqus


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

Home | PowerPoint | Photoshop | PowerPoint Templates | PowerPoint Tutorials | Blog | Notes | Ezine | Advertise | Feedback | Site Map | About Us | Contact Us

Link to Us | Privacy | Testimonials

PowerPoint Backgrounds | Christian PowerPoint Backgrounds | Business PowerPoint Presentation Templates

Plagiarism will be detected by Copyscape

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

since November 02, 2000