Bill Manville has posted code that retrieves all the files in a folder (and its
subfolders):
http://groups.google.com/[email protected]
I modified it ever so slightly to just bring back the .URL files. (I think
that's what the extension is for the shortcuts to the web in Favorites. (I
guessed that you only wanted internet favorites??).
Option Explicit
Option Base 1
Dim aFiles() As String
Dim iFile As Long
Sub testme01()
Dim oRow As Long
Dim wks As Worksheet
Dim wShell As Object 'As IWshShell_Class
Dim myLink As Object 'As IWshRuntimeLibrary.WshShortcut
'Set wShell = New IWshShell_Class
Set wShell = CreateObject("WScript.Shell")
Set wks = Worksheets.Add
Call ListFilesInDirectory("C:\windows\favorites\")
For oRow = LBound(aFiles) To UBound(aFiles)
Set myLink = wShell.createshortcut(aFiles(oRow))
wks.Cells(oRow, 1).Value = aFiles(oRow)
'wks.Cells(oRow, 2).Value = myLink.targetpath
'or to make it a hyperlink
wks.Cells(oRow, 2).Formula = "=hyperlink(" & Chr(34) _
& myLink.targetpath & Chr(34) & ")"
Next
End Sub
Sub ListFilesInDirectory(Directory As String)
Dim aDirs() As String, iDir As Long, stFile As String
' use Dir function to find files and directories in Directory
' look for directories and build a separate array of them
' note that Dir returns files as well as directories when vbDirectory
' specified
iDir = 0
stFile = Directory & Dir(Directory & "*.*", vbDirectory)
Do While stFile <> Directory
If Right(stFile, 2) = "\." Or Right(stFile, 3) = "\.." Then
' do nothing - GetAttr doesn't like these directories
ElseIf GetAttr(stFile) = vbDirectory Then
' add to local array of directories
iDir = iDir + 1
ReDim Preserve aDirs(iDir)
aDirs(iDir) = stFile
Else
'just return .URL files
' add to global array of files
If LCase(stFile) Like "*.url" Then
iFile = iFile + 1
ReDim Preserve aFiles(iFile)
aFiles(iFile) = stFile
End If
End If
stFile = Directory & Dir()
Loop
' now, for any directories in aDirs call self recursively
If iDir > 0 Then
For iDir = 1 To UBound(aDirs)
ListFilesInDirectory aDirs(iDir) & Application.PathSeparator
Next iDir
End If
End Sub
Change this line to your favorites folder.
Call ListFilesInDirectory("C:\windows\favorites\")