Thread: [Solved] Links to other files
View Single Post
 
Old 10-19-2015, 02:52 PM
macropod's Avatar
macropod macropod is offline Windows 7 64bit Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,369
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Quote:
Originally Posted by Officer_Bierschnitt View Post
Running that macro over all Excel_files is unfortunately not an option, IT would never allow it - but I can use it on one file at a time all right.
The following macro allows you to select a folder and extract the link data for all Excel files in that folder.
Code:
Sub Demo()
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
Dim strFolder As String, strFile As String, aLnks
Dim xlWkBk As Workbook, xlWkSht As Worksheet, i As Long, j As Long
Set xlWkSht = ThisWorkbook.Sheets(1)
strFolder = GetFolder
If strFolder = "" Then Exit Sub
j = xlWkSht.UsedRange.Cells.SpecialCells(xlCellTypeLastCell).Row + 1
strFile = Dir(strFolder & "\*.xls", vbNormal)
While strFile <> ""
  If strFolder & "\" & strFile <> ThisWorkbook.FullName Then
    Set xlWkBk = Workbooks.Open(Filename:=strFolder & "\" & strFile, AddToMRU:=False, ReadOnly:=True)
    j = j + 1
    With xlWkBk
      xlWkSht.Cells(j, 1).Value = .FullName
      On Error Resume Next
      aLnks = .LinkSources(xlExcelLinks)
      For i = 1 To UBound(aLnks)
        j = j + 1
        xlWkSht.Cells(j, 2).Value = aLnks(i)
      Next i
      aLnks = .LinkSources(xlOLELinks)
      For i = 1 To UBound(aLnks)
        j = j + 1
        xlWkSht.Cells(j, 2).Value = aLnks(i)
      Next i
      j = j + 1
      .Close SaveChanges:=False
    End With
  End If
  strFile = Dir()
Wend
Set xlWkBk = Nothing
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True
End Sub
 
Function GetFolder() As String
Dim oFolder As Object
GetFolder = ""
Set oFolder = CreateObject("Shell.Application").BrowseForFolder(0, "Choose a folder", 0)
If (Not oFolder Is Nothing) Then GetFolder = oFolder.Items.Item.Path
Set oFolder = Nothing
End Function
You'll probably find it takes only a few minutes to process even a very large folder.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote