Create an index or table of contents (TOC) with links to a folder full of PPT files
You have a whole collection of PPT files you want to link to from a single PPT "menu" slide or presentation. While you can insert links, one by one, to each file in the folder where the PPT files are stored, that's tedious.
Macros to the rescue.
Run this macro and it'll produce a series of text shapes on the current slide, one per PPT file in the directory pointed to by targetFileSpec (which you'll need to edit below).
Each one also becomes a link TO the PPT file. For lots of files, you'll need to do a little reformatting/spacing and aligning, but this'll whip up the basic "index" page for you in under a second.
Sub MakeLotsOfLinks() Dim TheTextBox As Shape Dim FileName As String Dim LinkRange As TextRange Dim Top, Left, width, height As Double Dim targetFileSpec As String ' EDIT THIS: Replace the text between the equals signs ' with the path to the folder where your PPT files are stored targetFileSpec = "D:\Test\*.PPT" ' Rather arbitrary starting positions for text box Top = 18# Left = 18# width = 600# height = 30# ' Get the first matching file FileName = Dir$(targetFileSpec) ' And if somebody's home: While FileName <> "" ' Add a textbox to hold the link Set TheTextBox = ActiveWindow.Selection.SlideRange.Shapes.AddTextbox(msoTextOrientationHorizontal, _ Left, _ Top, _ width, _ height) TheTextBox.TextFrame.TextRange.Text = FileName Set LinkRange = TheTextBox.TextFrame.TextRange.Characters(Start:=1, Length:=Len(FileName)) LinkRange.ActionSettings(ppMouseClick).Hyperlink.Address = FileName ' Get the next file FileName = Dir$ ' move the text box start position down Top = Top + height Wend End Sub
Or put the links in a table
If you prefer to have the links in a table, you can use the following code.
First, create a table with enough cells to hold the number of files you'll be linking to. Then with the table selected, run this:
Sub MakeLotsOfLinksInATable() Dim FileName As String Dim LinkRange As TextRange Dim targetFileSpec As String Dim aFileNames() As String Dim oTable As Shape Dim x As Long Dim y As Long Dim lPointer As Long ' EDIT THIS: Replace the text between the equals signs ' with the path to the folder where your PPT files are stored targetFileSpec = "c:\myfiles\*.PPT" ReDim aFileNames(1 To 1) As String ' Fill the array with filenames FileName = Dir$(targetFileSpec) ' And if files are found: While FileName <> "" aFileNames(UBound(aFileNames)) = FileName FileName = Dir$ ReDim Preserve aFileNames(1 To UBound(aFileNames) + 1) As String Wend ' that leaves us with blank array entry; remove it: ReDim Preserve aFileNames(1 To UBound(aFileNames) - 1) As String ' now use the table Set oTable = ActiveWindow.Selection.ShapeRange(1) lPointer = 1 For y = 1 To oTable.Table.Rows.Count For x = 1 To oTable.Table.Columns.Count oTable.Table.Cell(y, x).Shape.TextFrame.TextRange.Text = aFileNames(lPointer) Set LinkRange = _ oTable.Table.Cell(y, x).Shape.TextFrame.TextRange.Characters(Start:=1, Length:=Len(aFileNames(lPointer))) LinkRange.ActionSettings(ppMouseClick).Hyperlink.Address = aFileNames(lPointer) lPointer = lPointer + 1 Next ' x Next ' y End Sub
See How do I use VBA code in PowerPoint? to learn how to use this example code.
Notes and Caveats
The links this produces are pathless, so you can move your collection of PowerPoint files from one computer to another easily. As long as your "index" PowerPoint file and all of the linked PPT files are together in the same folder, the links will work.
If the presentations are served from the web rather than a local drive, network drive or CD, the links won't work.
Also, due to a bug in PowerPoint, if you start PowerPoint then choose the index file from the Most Recently Used list on the File menu, PowerPoint doesn't properly set the default folder, so it won't find the linked files. Use any other method to open the presentation:
- Double-click the presentation's icon
- Start PowerPoint, choose File, Open and browse to the presentation
- Drag the presentation's icon onto the PPT icon or into a running copy of PowerPoint