Hi, Aqif,
Thanks for your reply! Since my original post, I discovered that the code was failing to pick up over half of the links that were actually in my Favorites folder. Upon further tinkering, I finally arrived at a good solution. The key is the function GetURLFromShortcut() ---- that picks up all links. I have included the code for my main scan loop and the function below for you (and anyone else who may be interested. At least I think I've solved the original VBA problem, with help from the other replys to my post (thank you very much for tips!!).
In DirToScan, "XXXXXXXXX" is whatever username your system set up for you. The main proc populates the FavLinks table with the full pathname (datatype TEXT(255)) of the .url file and the corresponding URL (datatype Hyperlink). This could be tweaked however you like.
I also print the URL's to a .txt file, one link per line. I then wrote a PHP page to read this file and try to connect to each URL and return the status of the attempt. I don't have this quite right yet. It is returning a lot of false negatives --- i.e., it tells me a link failed when I know for sure the link is good. So I need to work on that some more --- to resolve that issue and also to return the results back into the FavLinks table, so that I can build a good form telling me the results of my scan. I'm still not sure what is the best way to test the links efficiently and so that the results are accurate.
For a test you could try these, which I know are good links:
Path = C:\Documents and Settings\XXXXXXX\Favorites\Computers and Internet\Microsoft\Microsoft Press.url
Logical File Name = Microsoft Press
URL =
Path = C:\Documents and Settings\XXXXXXX\Favorites\AmateurRadio\Digital and PSK31\NB6Z - Digital HF Ham Radio.url
Logical File Name = NB6Z - Digital HF Ham Radio
URL =
With some more tweaking, I think I can get this into a very good, quick and efficient way to check the links in one's Favorite folders. Would appreciate any tips you might have. Also please let me know if you need any more assistance. Perhaps together we can come up with a super way to do this!!
Regards --- Bob
================= C O D E F O L L O W S ============================
Public Sub ScanFavDir(DirName As String)
Dim rstFS As New ADODB.Recordset
Dim cnn As ADODB.Connection
Dim Jdx As Long
Dim NumFiles As Long
Dim FullFileName As String
Dim URLName As String
Dim URLFile As String
Dim DirToScan As String
ClearRecSet "FavLinks"
Set cnn = CurrentProject.Connection
Set rstFS = New ADODB.Recordset
rstFS.Open "FavLinks", cnn, adOpenStatic, adLockOptimistic
DirToScan = "C:\Documents and Settings\XXXXXXXXX\Favorites\" & DirName
URLFile = "C:\BobD\ZScan\FavURL.txt"
Open URLFile For Output As #1
With Application.FileSearch
.LookIn = DirToScan
.FileName = "*.url"
.SearchSubFolders = True
.FileType = msoFileTypeAllFiles
If .Execute > 0 Then
NumFiles = .FoundFiles.Count
For Jdx = 1 To .FoundFiles.Count
FullFileName = .FoundFiles(Jdx)
URLName = GetURLFromShortcut(FullFileName)
rstFS.AddNew
rstFS!FavName = FullFileName
rstFS!FavURL = URLName
rstFS.Update
Debug.Print Jdx, FullFileName, URLName
Print #1, URLName
'------ Application.FollowHyperlink FullFileName, , True, False
Next Jdx
Else
MsgBox "No files were found in this directory", vbInformation
End If
End With
Close #1
rstFS.Close
cnn.Close
End Sub
Public Function GetURLFromShortcut(strShortcut As String) As String
Dim WSHShell As Object
Dim URLShortcut As Object
Set WSHShell = CreateObject("WScript.Shell")
Set URLShortcut = WSHShell.CreateShortcut(strShortcut)
GetURLFromShortcut = URLShortcut.TargetPath
End Function