How to add Bookmark to Favorites folder
Posted on January 5, 2009
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 | 'Internet - How to add Bookmark to Favorites folder Option Explicit Private Declare Function SHGetSpecialFolderLocation Lib "shell32.dll" (ByVal hwndOwner As Long, _ ByVal nFolder As SpecialShellFolderIDs, pidl As Long) As Long Private Declare Function SHGetPathFromIDList Lib "shell32.dll" Alias "SHGetPathFromIDListA" _ (ByVal pidl As Long, ByVal pszPath As String) As Long Private Declare Sub CoTaskMemFree Lib "ole32.dll" (ByVal pv As Long) Public Enum SpecialShellFolderIDs CSIDL_DESKTOP = &H0 CSIDL_INTERNET = &H1 CSIDL_PROGRAMS = &H2 CSIDL_CONTROLS = &H3 CSIDL_PRINTERS = &H4 CSIDL_PERSONAL = &H5 CSIDL_FAVORITES = &H6 CSIDL_STARTUP = &H7 CSIDL_RECENT = &H8 CSIDL_SENDTO = &H9 CSIDL_BITBUCKET = &HA CSIDL_STARTMENU = &HB CSIDL_DESKTOPDIRECTORY = &H10 CSIDL_DRIVES = &H11 CSIDL_NETWORK = &H12 CSIDL_NETHOOD = &H13 CSIDL_FONTS = &H14 CSIDL_TEMPLATES = &H15 CSIDL_COMMON_STARTMENU = &H16 CSIDL_COMMON_PROGRAMS = &H17 CSIDL_COMMON_STARTUP = &H18 CSIDL_COMMON_DESKTOPDIRECTORY = &H19 CSIDL_APPDATA = &H1A CSIDL_PRINTHOOD = &H1B CSIDL_ALTSTARTUP = &H1D CSIDL_COMMON_ALTSTARTUP = &H1E CSIDL_COMMON_FAVORITES = &H1F CSIDL_INTERNET_CACHE = &H20 CSIDL_COOKIES = &H21 CSIDL_HISTORY = &H22 End Enum Public Sub AddFavorite(SiteName As String, URL As String) Dim pidl As Long Dim intFile As Integer Dim strFullPath As String On Error GoTo ErrorHandler intFile = FreeFile strFullPath = Space(255) 'Check the API for the folder existence and location If SHGetSpecialFolderLocation(0, CSIDL_FAVORITES, pidl) = 0 Then If pidl Then If SHGetPathFromIDList(pidl, strFullPath) Then 'Trim any null characters If InStr(1, strFullPath, chr ( 0 ) ) Then strFullPath = Mid(strFullPath, 1, InStr(1, strFullPath, chr ( 0 ) ) - 1) End If ' Add back slash, if none exists If Right(strFullPath, 1) <> "\" Then strFullPath = strFullPath & "\" End If ' Create the link strFullPath = strFullPath & SiteName & ".URL" Open strFullPath For Output As #intFile Print #intFile, "[InternetShortcut]" Print #intFile, "URL=" & URL Close #intFile End If CoTaskMemFree pidl End If End If ErrorHandler: End Sub 'How can I call this function: Private Sub Form_Load() AddFavorite "CodeItBetter", "http://www.codeitbetter.com/" End Sub |