K
killianbannon
I have a macro which is meant to update any OLE links within PPT from
Excel (both 2000). The spreadsheet opens up a directory, looks for any
ppt or pps files and then opens them.
It searches for linked objects and if there are eny it then scans
through a column (containing current paths) in the spreadsheet to see
if it is there and if so it then replaces with the corresponding value
in column D.
Needless to say it doesn't work.
Any ideas?
(I have this working for links within Excel perfectly - its just PPT
that won't cooperate!)
My code is based on what appears to be the only way to do this -
http://www.rdpslides.com/pptfaq/FAQ00759.htm
Sub replaceExternalLinks(lookinPath)
Dim openedWorkBook As Workbook
Dim ws As Worksheet
Dim Cell As Object
Dim sheet_cell, rng As Range
Dim thisWB As String
Dim linkArray, vArrayItem, protectedSheetArray As Variant
Dim newValue, newFormula As Variant
Dim strFolderName, strFileName As String
Dim macroWorkbook, old_Folder, new_Folder As String
Dim totalDriveRows As Long
Dim loopRows As Long
Dim countMatchingLinks As Integer
Dim currentlyOpenWorkBooks As Integer
Dim oPPTApp As PowerPoint.Application
Dim oPPTPres As PowerPoint.Presentation
Dim oSld As Slide
Dim oSh As Shape
'Dim sPresentationFile As String
''''''''''''''''''''''''
'On Error Resume Next
Set oPPTApp = New PowerPoint.Application
oPPTApp.Visible = True
macroWorkbook = ActiveWorkbook.Name
Application.ScreenUpdating = False
totalDriveRows = ActiveWorkbook.Sheets("Mapping
Data").UsedRange.Rows.Count
'''''''''''''''''
'open the PPT/PPS
With Application.FileSearch
.NewSearch
.LookIn = "C:\someFolder"
.SearchSubFolders = False
.Filename = ".ppt;.pps"
If .Execute > 0 Then
Dim vaFileName As Variant
For Each vaFileName In .FoundFiles
If vaFileName <> lookinPath & "\" & macroWorkbook Then
Application.DisplayAlerts = False
Application.EnableEvents = False
Application.AskToUpdateLinks = False
Set oPPTPres =
oPPTApp.Presentations.Open(vaFileName)
oPPTApp.WindowState = ppWindowMinimized
Dim sOldPath As String
Dim sNewPath As String
For Each oSld In
oPPTPres.Application.ActivePresentation.Slides 'oPPTPres.Slides
For Each oSh In
oPPTPres.Application.ActivePresentation.Slides.Shapes
' Change only linked OLE objects
If oSh.Type = msoLinkedOLEObject Then
For loopRows = 4 To totalDriveRows
'start looking @ row 4
Workbooks(macroWorkbook).Activate
ActiveWorkbook.Worksheets("Mapping Data").Activate
If
ActiveWorkbook.Worksheets("Mapping Data").Range("A" & loopRows).Value
<> "" And ActiveWorkbook.Worksheets("Mapping Data").Range("D" &
loopRows).Value <> "" And ActiveWorkbook.Worksheets("Mapping
Data").Range("A" & loopRows).Value <> "h" Then
sOldPath =
ActiveWorkbook.Sheets("Mapping Data").Range("A" & loopRows).Value
sNewPath =
ActiveWorkbook.Sheets("Mapping Data").Range("D" & loopRows).Value
On Error Resume Next
If
InStr(oSh.LinkFormat.SourceFullName, sOldPath, vbTextCompare) Then Exit
Sub
If
Len(Dir$(Replace(oSh.LinkFormat.SourceFullName, sOldPath, sNewPath))) >
0 Then
linkArray = linkArray &
"1" & vaFileName & "^," ' ActivePresentation.Path
linkArray = linkArray &
"2" & sOldPath & "^,"
oSh.LinkFormat.SourceFullName = Replace(oSh.LinkFormat.SourceFullName,
sOldPath, sNewPath)
linkArray = linkArray &
"3" & sNewPath & "^,"
oPPTPres.Save
End If
End If
Next ' looprows
End If
Next ' shape
Next ' slide
oPPTPres.Save
oPPTPres.Close
oPPTApp.Quit
Set oPPTPres = Nothing
Application.EnableEvents = True
Application.DisplayAlerts = True
End If
Next vaFileName
End If
End With
Application.ScreenUpdating = True
Set oPPTApp = Nothing
Workbooks(macroWorkbook).Worksheets("Links Log").Activate
Dim linkPart As Variant
Dim i, j As Integer
i = 0
If Right(linkArray, 2) = "^," Then linkArray = Left(linkArray,
Len(linkArray) - 2)
For Each linkPart In Split(linkArray, "^,")
ActiveCell.Value = linkPart
i = i + 1
If i = 3 Then
i = 0
ActiveCell.Offset(1, -2).Select
Else
ActiveCell.Offset(0, 1).Select
End If
ActiveCell = Selection
Next linkPart
Workbooks(macroWorkbook).Save
Application.ScreenUpdating = True
End Sub
Excel (both 2000). The spreadsheet opens up a directory, looks for any
ppt or pps files and then opens them.
It searches for linked objects and if there are eny it then scans
through a column (containing current paths) in the spreadsheet to see
if it is there and if so it then replaces with the corresponding value
in column D.
Needless to say it doesn't work.
Any ideas?
(I have this working for links within Excel perfectly - its just PPT
that won't cooperate!)
My code is based on what appears to be the only way to do this -
http://www.rdpslides.com/pptfaq/FAQ00759.htm
Sub replaceExternalLinks(lookinPath)
Dim openedWorkBook As Workbook
Dim ws As Worksheet
Dim Cell As Object
Dim sheet_cell, rng As Range
Dim thisWB As String
Dim linkArray, vArrayItem, protectedSheetArray As Variant
Dim newValue, newFormula As Variant
Dim strFolderName, strFileName As String
Dim macroWorkbook, old_Folder, new_Folder As String
Dim totalDriveRows As Long
Dim loopRows As Long
Dim countMatchingLinks As Integer
Dim currentlyOpenWorkBooks As Integer
Dim oPPTApp As PowerPoint.Application
Dim oPPTPres As PowerPoint.Presentation
Dim oSld As Slide
Dim oSh As Shape
'Dim sPresentationFile As String
''''''''''''''''''''''''
'On Error Resume Next
Set oPPTApp = New PowerPoint.Application
oPPTApp.Visible = True
macroWorkbook = ActiveWorkbook.Name
Application.ScreenUpdating = False
totalDriveRows = ActiveWorkbook.Sheets("Mapping
Data").UsedRange.Rows.Count
'''''''''''''''''
'open the PPT/PPS
With Application.FileSearch
.NewSearch
.LookIn = "C:\someFolder"
.SearchSubFolders = False
.Filename = ".ppt;.pps"
If .Execute > 0 Then
Dim vaFileName As Variant
For Each vaFileName In .FoundFiles
If vaFileName <> lookinPath & "\" & macroWorkbook Then
Application.DisplayAlerts = False
Application.EnableEvents = False
Application.AskToUpdateLinks = False
Set oPPTPres =
oPPTApp.Presentations.Open(vaFileName)
oPPTApp.WindowState = ppWindowMinimized
Dim sOldPath As String
Dim sNewPath As String
For Each oSld In
oPPTPres.Application.ActivePresentation.Slides 'oPPTPres.Slides
For Each oSh In
oPPTPres.Application.ActivePresentation.Slides.Shapes
' Change only linked OLE objects
If oSh.Type = msoLinkedOLEObject Then
For loopRows = 4 To totalDriveRows
'start looking @ row 4
Workbooks(macroWorkbook).Activate
ActiveWorkbook.Worksheets("Mapping Data").Activate
If
ActiveWorkbook.Worksheets("Mapping Data").Range("A" & loopRows).Value
<> "" And ActiveWorkbook.Worksheets("Mapping Data").Range("D" &
loopRows).Value <> "" And ActiveWorkbook.Worksheets("Mapping
Data").Range("A" & loopRows).Value <> "h" Then
sOldPath =
ActiveWorkbook.Sheets("Mapping Data").Range("A" & loopRows).Value
sNewPath =
ActiveWorkbook.Sheets("Mapping Data").Range("D" & loopRows).Value
On Error Resume Next
If
InStr(oSh.LinkFormat.SourceFullName, sOldPath, vbTextCompare) Then Exit
Sub
If
Len(Dir$(Replace(oSh.LinkFormat.SourceFullName, sOldPath, sNewPath))) >
0 Then
linkArray = linkArray &
"1" & vaFileName & "^," ' ActivePresentation.Path
linkArray = linkArray &
"2" & sOldPath & "^,"
oSh.LinkFormat.SourceFullName = Replace(oSh.LinkFormat.SourceFullName,
sOldPath, sNewPath)
linkArray = linkArray &
"3" & sNewPath & "^,"
oPPTPres.Save
End If
End If
Next ' looprows
End If
Next ' shape
Next ' slide
oPPTPres.Save
oPPTPres.Close
oPPTApp.Quit
Set oPPTPres = Nothing
Application.EnableEvents = True
Application.DisplayAlerts = True
End If
Next vaFileName
End If
End With
Application.ScreenUpdating = True
Set oPPTApp = Nothing
Workbooks(macroWorkbook).Worksheets("Links Log").Activate
Dim linkPart As Variant
Dim i, j As Integer
i = 0
If Right(linkArray, 2) = "^," Then linkArray = Left(linkArray,
Len(linkArray) - 2)
For Each linkPart In Split(linkArray, "^,")
ActiveCell.Value = linkPart
i = i + 1
If i = 3 Then
i = 0
ActiveCell.Offset(1, -2).Select
Else
ActiveCell.Offset(0, 1).Select
End If
ActiveCell = Selection
Next linkPart
Workbooks(macroWorkbook).Save
Application.ScreenUpdating = True
End Sub