Bufger
09-09-2013, 04:44 AM
Using Powerpoint 2010.
There are 2 challenges i'm facing with this small project.
I'm trying to have one master blank presentation with a pull macro to pull in slides from multiple directories (ie other people do the slides on a common format, put them in a shared directory area and this macro pulls them in to one presentation.
ie it pulls from U:\ProjectX\Team\MeetingInputs\Team1 (Team2, Team3) etc
I want it to pull all slides from each incase the number of slides differed week on week.
Heres the latest ive been messing about with:
Sub Pull()
Dim SrcDir As String, SrcFile As String
SrcDir = PickDir()
If SrcDir = "" Then Exit Sub
SrcFile = Dir(SrcDir & "Input.pptx")
Do While SrcFile <> "Input.pptx"
ImportFromPPT SrcDir + "\" + SrcFile, 1, 2
SrcFile = Dir()
Loop
End Sub
Private Function PickDir() As String
Dim FD As FileDialog
PickDir = "U:\ProjectX\Team\MeetingInputs\Team1"
Set FD = Application.FileDialog(msoFileDialogFolderPicker)
With FD
.Title = "U:\ProjectX\Team\MeetingInputs\Team1"
.AllowMultiSelect = False
.Show
If .SelectedItems.Count <> 0 Then
PickDir = .SelectedItems(1)
End If
End With
End Function
The second challenging part is getting it to keep hyperlinks hitting the correct pages by slide title rather than number! For that i've tried the following without success (no errors, just doesnt seem to work):
Option Explicit
Sub ResetLinksToTitles()
Dim oPres As Presentation
Dim oSld As Slide
Dim I As Integer
Dim Titles() As String
Dim Target() As String
Dim TargetSlideIndex As Long
Dim sNewLink As String
Dim Ctr As Long
Set oPres = ActivePresentation
Ctr = 0
'Load all the titles
ReDim Titles(1 To oPres.Slides.Count)
For I = 1 To oPres.Slides.Count
If oPres.Slides(1).Shapes.HasTitle Then
If oPres.Slides(1).Shapes.Title.TextFrame.HasText Then
Titles(I) = oPres.Slides(I).Shapes.Title.TextFrame.TextRange.Text
End If
End If
Next
For Each oSld In oPres.Slides
For I = 1 To oSld.Hyperlinks.Count
With oSld.Hyperlinks(I)
If .Address = "" Then
Erase Target
'Get the link info and parse it.
Target = Split(.SubAddress, ",")
'Locate a slide for that title, if any.
If Len(Trim(Target(2))) > 0 Then
TargetSlideIndex = FindSlideByTitle(Target(2), Titles)
If TargetSlideIndex > 0 Then
' Check if the id of the slide found already matches the existing link
If Val(Target(0)) <> oPres.Slides(TargetSlideIndex).SlideID Then
' If not then update the link with the new id and slide index.
sNewLink = CStr(oPres.Slides(TargetSlideIndex).SlideID) & _
"," & CStr(TargetSlideIndex) & "," & Target(2)
Debug.Print "Changing " & .SubAddress & " to " & sNewLink
.SubAddress = sNewLink
Ctr = Ctr + 1
End If
End If
End If
End If
End With
Next
Next
Debug.Print CStr(Ctr) & " links changed."
End Sub
Function FindSlideByTitle(Title As String, Titles() As String) As Long
Dim I As Integer
FindSlideByTitle = -1
For I = 1 To UBound(Titles)
If Title = Titles(I) Then
FindSlideByTitle = I
Exit Function
End If
Next
End Function
I'd really appreciate somebody with experience helping me out with this. I havent written a macro in years and i'm feeling a little short of ideas now! I dont think i'm approaching it the right way.
Many thanks,
Andy
There are 2 challenges i'm facing with this small project.
I'm trying to have one master blank presentation with a pull macro to pull in slides from multiple directories (ie other people do the slides on a common format, put them in a shared directory area and this macro pulls them in to one presentation.
ie it pulls from U:\ProjectX\Team\MeetingInputs\Team1 (Team2, Team3) etc
I want it to pull all slides from each incase the number of slides differed week on week.
Heres the latest ive been messing about with:
Sub Pull()
Dim SrcDir As String, SrcFile As String
SrcDir = PickDir()
If SrcDir = "" Then Exit Sub
SrcFile = Dir(SrcDir & "Input.pptx")
Do While SrcFile <> "Input.pptx"
ImportFromPPT SrcDir + "\" + SrcFile, 1, 2
SrcFile = Dir()
Loop
End Sub
Private Function PickDir() As String
Dim FD As FileDialog
PickDir = "U:\ProjectX\Team\MeetingInputs\Team1"
Set FD = Application.FileDialog(msoFileDialogFolderPicker)
With FD
.Title = "U:\ProjectX\Team\MeetingInputs\Team1"
.AllowMultiSelect = False
.Show
If .SelectedItems.Count <> 0 Then
PickDir = .SelectedItems(1)
End If
End With
End Function
The second challenging part is getting it to keep hyperlinks hitting the correct pages by slide title rather than number! For that i've tried the following without success (no errors, just doesnt seem to work):
Option Explicit
Sub ResetLinksToTitles()
Dim oPres As Presentation
Dim oSld As Slide
Dim I As Integer
Dim Titles() As String
Dim Target() As String
Dim TargetSlideIndex As Long
Dim sNewLink As String
Dim Ctr As Long
Set oPres = ActivePresentation
Ctr = 0
'Load all the titles
ReDim Titles(1 To oPres.Slides.Count)
For I = 1 To oPres.Slides.Count
If oPres.Slides(1).Shapes.HasTitle Then
If oPres.Slides(1).Shapes.Title.TextFrame.HasText Then
Titles(I) = oPres.Slides(I).Shapes.Title.TextFrame.TextRange.Text
End If
End If
Next
For Each oSld In oPres.Slides
For I = 1 To oSld.Hyperlinks.Count
With oSld.Hyperlinks(I)
If .Address = "" Then
Erase Target
'Get the link info and parse it.
Target = Split(.SubAddress, ",")
'Locate a slide for that title, if any.
If Len(Trim(Target(2))) > 0 Then
TargetSlideIndex = FindSlideByTitle(Target(2), Titles)
If TargetSlideIndex > 0 Then
' Check if the id of the slide found already matches the existing link
If Val(Target(0)) <> oPres.Slides(TargetSlideIndex).SlideID Then
' If not then update the link with the new id and slide index.
sNewLink = CStr(oPres.Slides(TargetSlideIndex).SlideID) & _
"," & CStr(TargetSlideIndex) & "," & Target(2)
Debug.Print "Changing " & .SubAddress & " to " & sNewLink
.SubAddress = sNewLink
Ctr = Ctr + 1
End If
End If
End If
End If
End With
Next
Next
Debug.Print CStr(Ctr) & " links changed."
End Sub
Function FindSlideByTitle(Title As String, Titles() As String) As Long
Dim I As Integer
FindSlideByTitle = -1
For I = 1 To UBound(Titles)
If Title = Titles(I) Then
FindSlideByTitle = I
Exit Function
End If
Next
End Function
I'd really appreciate somebody with experience helping me out with this. I havent written a macro in years and i'm feeling a little short of ideas now! I dont think i'm approaching it the right way.
Many thanks,
Andy