Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 15
Default Copy Internet Favorites To Workbook

Would anyone have a VBA procedure that would copy your
favorite URLs on your internet toolbar to an Excel
worksheet? I would like to be able to have an Excel
worksheet that I can update frequently that contains a
list of my favorite URLs.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 226
Default Copy Internet Favorites To Workbook

This seems to work ok. Just put it in a standard module and run the
"ExtractFavorites" sub

Option Explicit

Const CSIDL_FAVORITES = &H6
Const NOERROR = 0

Private Declare Function SHGetSpecialFolderLocation Lib _
"shell32.dll" (ByVal hwndOwner As Long, ByVal nFolder As Long, _
pidl As ITEMIDLIST) As Long
Private Declare Function SHGetPathFromIDList Lib "shell32.dll" _
Alias "SHGetPathFromIDListA" (ByVal pidl As Long, _
ByVal pszPath As String) As Long

Private Type ****EMID
cb As Long
abID As Byte
End Type
Private Type ITEMIDLIST
mkid As ****EMID
End Type

Sub ExtractFavorites()
Dim Pth As String
Dim i As Long
Dim Rng As Range
Pth = GetSpecialfolder(CSIDL_FAVORITES)
If Len(Pth) 0 Then

Application.ScreenUpdating = False

With Workbooks.Add(xlWorksheet).Worksheets(1)
.Name = "Favorites"
With .Range("A1").Resize(1, 3)
.Value = Array("Folder", "Name", "URL")
.Font.Bold = True
End With
End With

With Application.FileSearch
.NewSearch

.FileType = msoFileTypeAllFiles
.LookIn = Pth
.SearchSubFolders = True

If .Execute() 0 Then
For i = 1 To .FoundFiles.Count
If .FoundFiles(i) Like "*.url" Then
Set Rng = Cells(Rows.Count, 1).End(xlUp).Offset(1)

Rng.Value = GetPath(.FoundFiles(i))
Rng.Offset(, 1).Value = GetName(.FoundFiles(i))
Rng.Offset(, 2).Value = GetURL(.FoundFiles(i))

Rng.Offset(, 2).Hyperlinks.Add Rng.Offset(, 2),
Rng.Offset(, 2).Value
End If
Next i
End If
End With

Range("A1").CurrentRegion.Sort Range("A1"), xlAscending,
Header:=xlYes

Application.ScreenUpdating = True

End If
End Sub

Private Function GetSpecialfolder(CSIDL As Long) As String
Dim r As Long
Dim Path$
Dim IDL As ITEMIDLIST
'Get the special folder
r = SHGetSpecialFolderLocation(100, CSIDL, IDL)
If r = NOERROR Then
'Create a buffer
Path$ = Space$(512)
'Get the path from the IDList
r = SHGetPathFromIDList(ByVal IDL.mkid.cb, ByVal Path$)
'Remove the unnecessary chr$(0)'s
GetSpecialfolder = Left$(Path, InStr(Path, Chr$(0)) - 1)
Exit Function
End If
GetSpecialfolder = ""
End Function

Private Function GetPath(FileName As String) As String
On Error Resume Next
GetPath = Left$(FileName, Len(FileName) - Len(GetName(FileName)) - _
Len(Application.PathSeparator))
End Function

Private Function GetName(FileName As String) As String
#If VBA6 Then
Dim Ar As Variant
Ar = Split(FileName, Application.PathSeparator)
GetName = Ar(UBound(Ar))
#Else
Dim St As String, Ctr As Long, i As Long
St = FileName
Ctr = (Len(St) - Len(Application.Substitute(St, _
Application.PathSeparator, ""))) /
Len(Application.PathSeparator)
St = Application.Substitute(St, Application.PathSeparator,
Chr$(127), Ctr)
GetName = Mid$(St, InStr(1, St, Chr$(127), 1) + 1)
#End If
End Function

Private Function GetURL(FileName As String) As String
Dim Fl As Long

Fl = FreeFile()

Open FileName For Input Access Read As #Fl

Do While Not EOF(1)
Line Input #1, GetURL
If GetURL Like "URL=*" Then
GetURL = Mid$(GetURL, 5)
GoTo exiting
End If
Loop
exiting:
Close #Fl
End Function


--
Regards

Juan Pablo González

"John Mansfield" wrote in message
...
Would anyone have a VBA procedure that would copy your
favorite URLs on your internet toolbar to an Excel
worksheet? I would like to be able to have an Excel
worksheet that I can update frequently that contains a
list of my favorite URLs.



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 15
Default Copy Internet Favorites To Workbook

Juan, thank you very much for your help with this.

John Mansfield

-----Original Message-----
This seems to work ok. Just put it in a standard module

and run the
"ExtractFavorites" sub

Option Explicit

Const CSIDL_FAVORITES = &H6
Const NOERROR = 0

Private Declare Function SHGetSpecialFolderLocation Lib _
"shell32.dll" (ByVal hwndOwner As Long, ByVal nFolder

As Long, _
pidl As ITEMIDLIST) As Long
Private Declare Function SHGetPathFromIDList

Lib "shell32.dll" _
Alias "SHGetPathFromIDListA" (ByVal pidl As Long, _
ByVal pszPath As String) As Long

Private Type ****EMID
cb As Long
abID As Byte
End Type
Private Type ITEMIDLIST
mkid As ****EMID
End Type

Sub ExtractFavorites()
Dim Pth As String
Dim i As Long
Dim Rng As Range
Pth = GetSpecialfolder(CSIDL_FAVORITES)
If Len(Pth) 0 Then

Application.ScreenUpdating = False

With Workbooks.Add(xlWorksheet).Worksheets(1)
.Name = "Favorites"
With .Range("A1").Resize(1, 3)
.Value = Array("Folder", "Name", "URL")
.Font.Bold = True
End With
End With

With Application.FileSearch
.NewSearch

.FileType = msoFileTypeAllFiles
.LookIn = Pth
.SearchSubFolders = True

If .Execute() 0 Then
For i = 1 To .FoundFiles.Count
If .FoundFiles(i) Like "*.url" Then
Set Rng = Cells(Rows.Count, 1).End

(xlUp).Offset(1)

Rng.Value = GetPath(.FoundFiles

(i))
Rng.Offset(, 1).Value = GetName

(.FoundFiles(i))
Rng.Offset(, 2).Value = GetURL

(.FoundFiles(i))

Rng.Offset(, 2).Hyperlinks.Add

Rng.Offset(, 2),
Rng.Offset(, 2).Value
End If
Next i
End If
End With

Range("A1").CurrentRegion.Sort Range("A1"),

xlAscending,
Header:=xlYes

Application.ScreenUpdating = True

End If
End Sub

Private Function GetSpecialfolder(CSIDL As Long) As String
Dim r As Long
Dim Path$
Dim IDL As ITEMIDLIST
'Get the special folder
r = SHGetSpecialFolderLocation(100, CSIDL, IDL)
If r = NOERROR Then
'Create a buffer
Path$ = Space$(512)
'Get the path from the IDList
r = SHGetPathFromIDList(ByVal IDL.mkid.cb, ByVal

Path$)
'Remove the unnecessary chr$(0)'s
GetSpecialfolder = Left$(Path, InStr(Path,

Chr$(0)) - 1)
Exit Function
End If
GetSpecialfolder = ""
End Function

Private Function GetPath(FileName As String) As String
On Error Resume Next
GetPath = Left$(FileName, Len(FileName) - Len(GetName

(FileName)) - _
Len(Application.PathSeparator))
End Function

Private Function GetName(FileName As String) As String
#If VBA6 Then
Dim Ar As Variant
Ar = Split(FileName, Application.PathSeparator)
GetName = Ar(UBound(Ar))
#Else
Dim St As String, Ctr As Long, i As Long
St = FileName
Ctr = (Len(St) - Len(Application.Substitute(St, _
Application.PathSeparator, ""))) /
Len(Application.PathSeparator)
St = Application.Substitute(St,

Application.PathSeparator,
Chr$(127), Ctr)
GetName = Mid$(St, InStr(1, St, Chr$(127), 1) + 1)
#End If
End Function

Private Function GetURL(FileName As String) As String
Dim Fl As Long

Fl = FreeFile()

Open FileName For Input Access Read As #Fl

Do While Not EOF(1)
Line Input #1, GetURL
If GetURL Like "URL=*" Then
GetURL = Mid$(GetURL, 5)
GoTo exiting
End If
Loop
exiting:
Close #Fl
End Function


--
Regards

Juan Pablo González

"John Mansfield"

wrote in message
...
Would anyone have a VBA procedure that would copy your
favorite URLs on your internet toolbar to an Excel
worksheet? I would like to be able to have an Excel
worksheet that I can update frequently that contains a
list of my favorite URLs.



.

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Copy data from internet to excel jj Excel Discussion (Misc queries) 6 October 3rd 08 03:39 PM
How do I copy a mailing list from the internet to Excel? jbutson Excel Discussion (Misc queries) 1 May 30th 07 06:01 PM
Workbook view with internet explorer Mike Excel Discussion (Misc queries) 0 January 22nd 07 12:09 PM
How do I share a workbook accross the internet? ryan Excel Discussion (Misc queries) 0 January 7th 06 05:32 PM
Download (copy) file from the internet Jos Vens Excel Programming 1 February 3rd 04 02:14 PM


All times are GMT +1. The time now is 12:54 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"