PDA

View Full Version : Add to favorites



Anne Troy
08-23-2004, 12:40 AM
I want a way to add a list of hyperlinks in a Word document to a folder under the user's favorites folder in IE.

Am I asking the impossible?

Don't try to provide code yet...just wondering.

jamescol
08-23-2004, 08:15 AM
Yes, this is possible.

fumei
08-23-2004, 09:14 AM
A list as a text file is of course possible, but I have been trying to save a hyperlink as a Internet shortcut (which is what i bel;ieve you asking for), and have not been able to do so, yet. The problem is that a shortcut is a Windows object, NOT a Word object.

There may be a API that can do it.

Anne Troy
08-23-2004, 09:17 AM
Actually, I've got a table in Word. Second column is the NAME of the shortcut. Fourth column is the hyperlink.

TonyJollans
08-23-2004, 09:37 AM
Gerry,

Try .. ActiveDocument.Hyperlinks(1).AddToFavorites

- obviously reference your own hyperlink :)

jamescol
08-23-2004, 10:03 AM
Tony,
The only limitation with that is you cannot specify subfolders under the Favorites menu. I may be missing something, but I understood it took an API call to create a Favorites subfolder and place a link in it.

James

TonyJollans
08-23-2004, 10:23 AM
An API is one way - moving it after the save is another.

jamescol
08-23-2004, 10:38 AM
Perhaps you could post an example when you get a chance. I have a small app that performs this function and could benefit from a pure VBA method.

Cheers,
James

Anne Troy
08-23-2004, 10:50 AM
Sure!!

TonyJollans
08-23-2004, 12:09 PM
Hi James,

I should learn to keep my mouth shut! :blush

I just asumed that because I could save and I could move that I could put the two together but no such luck.

The first problem is that I don't know what name the shortcut will be added as. If you use the dialog (which is not exposed to VBA anyway), the default name is the hyperlink's display text. If you use the addtofavorites method, it generates a name from the address. It is possible, if not elegant or efficient, to check what has been added to the favorites folder but the addtofavorites process will replace existing shortcuts of the same name so that is not enough and what you have to do is check the date and time for the most recent - possible with the fso I suppose, but, all in all, I'd stick with the API.

Kelly
08-23-2004, 09:42 PM
Fumei, James, and Tony,

I respect you all immensely, and therefore would be honored if you would look at my humble macro here and tell me if it's worth the bytes it took to write it. Whether you think it is elegant or pathetic, I will be grateful for your feedback either way.

I realize that this is a blatant hack/workaround, but since James says he may be able to "benefit from a pure VBA method," I figure what the heck.

I am running Windows XP and Word 2000, so I if my little hack is working for me and not for others, it may be helpful to compare systems.

I wrote this based on Dreamboat's description of a table, as in:

Second column is the NAME of the shortcut. Fourth column is the hyperlink
For now, my macro creates (apparently genuine and fully functional) Internet Shortcuts right on "C:\"

And it does indeed create them with the desired name. (not some unpredictable auto-generated name, but the precise name given by the user who wrote the table)

I haven't added anything for the address of the favorites folder yet, or for the subfolder.

Let me know!!!

Sub Make_Favorites_Links()

With ActiveDocument.Tables(1)

For x = 1 To .Rows.Count

SiteName = .Columns(2).Cells(x).Range.Text
SiteName = Left(SiteName, Len(SiteName) - 2)

SiteURL = .Columns(4).Cells(x).Range.Hyperlinks(1).Address

myString = "[DEFAULT]" & vbCr & "BASEURL=" & SiteURL & vbCr & _
"[InternetShortcut]" & vbCr & "URL=" & SiteURL

Dim myDoc As Document
Set myDoc = Documents.Add(, , , Visible:=False)

myDoc.Range.InsertBefore myString

myDoc.SaveAs "C:\" & SiteName & ".url", wdFormatText
myDoc.Close

Next x

End With

End Sub

Below: the sample doc that I have tested

TonyJollans
08-24-2004, 07:45 AM
Very clever Kelly. I haven't tested your sample but I believe you when you say it works.

I've done a bit of digging and MS seem to be pretty secretive about the format but from what I can see it looks good for the case in point. However, shortcut files can be more complex than that and I don't know whether it will work in all circumstances.

Kelly
08-24-2004, 08:15 AM
Very clever Kelly. I haven't tested your sample but I believe you when you say it works.

I've done a bit of digging and MS seem to be pretty secretive about the format but from what I can see it looks good for the case in point. However, shortcut files can be more complex than that and I don't know whether it will work in all circumstances.
Thanks!

Regarding the varying complexity of shortcut files.... you're definitely right, Tony, but that raises yet another question in my mind.

I found the following shortcut file on my computer:

[DEFAULT]
BASEURL=http://www.firstcallstaff.com/
[DOC#6#8]
BASEURL=http://www.firstcallstaff.com/FCOffNav.htm
ORIGURL=FCNav.html
[DOC#6#9#11]
BASEURL=http://www.firstcallstaff.com/FCtorloc.htm
ORIGURL=FCOpen2.html
[InternetShortcut]
URL=http://www.firstcallstaff.com/

And I found out that the complexity in this one is caused by the website's use of FRAMES.

When I use this shortcut, the only thing I see in the "address bar" (or whatever it's called) in IE is "http://www.firstcallstaff.com" HOWEVER the central frame is actually displaying the html from http://www.firstcallstaff.com/FCtorloc.htm (which as you can see is indicated within the shortcut file)

So here's where my question comes in...

Obviously, my macro wouldn't create a shortcut file like this one.
Yet.... I'm wondering if that would ever actually become an issue??
In order for the macro to NEED to make a special shortcut like this, then the HYPERLINK in word would need to contain such info rather than a simple web address.

So the question is: Is it possible for a hyperlink in Word to specify such details about frames?

(I'm not necessarily trying to be a "fervent defender" of my approach -- I have my own misgivings about it -- I'm just interested in this topic of The Nature of Shortcut Files as an intellectual exercise. why such secrecy by Microsoft about such a piddly thing?)

TonyJollans
08-24-2004, 08:56 AM
I agree completely, Kelly, and as I said I think your code is good for the case in point.

AFAIK the only way to add any information to a hyperlink in Word beyond a single address string is to use the SubAddress property (set via the Bookmark option in the dialog).

I just did an experiment and found that that information isn't included when you add a hyperlink to your favourites via the normal dialog anyway so even when Word has extra information it doesn't use it.

With a bit of trial and error testing it seems that all you actually need is ..

[InternetShortcut]
URL=whatever

So I would say we had a solution. Well done!

Kelly
08-24-2004, 09:08 AM
Cool!

I love all the extra experiments you did! That's awesome.