Open up an Internet-shortcut from VBA

K

Kalle

I would like to open a word document from Access but the document is an
internet-shortcut. I tried to get the file and the URL with FileSystemObject
and GetFile but it can´t recognize it as a file. Can anyone help.
Thanks

Kalle
 
K

Kalle

Thanks for the reply, Karl. But it can't read the URL in the
Internet-shortcut either.
 
K

Karl E. Peterson

Kalle said:
Thanks for the reply, Karl. But it can't read the URL in the
Internet-shortcut either.

Ah, I think I missed a key point. The trouble you're having is reading the
shortcut file? Those are actually INI files with a .URL extension. Drag
one into Notepad, to see its structure. No need to use the file system
object, although that's certainly an option. Using the CIniFile class I
wrote (http://vb.mvps.org/samples/kpIni), it's as simple as this:

Public Function GetLink(ByVal UrlFile As String) As String
Dim ini As New CIniFile
With ini
.FileName = UrlFile
.Section = "InternetShortcut"
GetLink = .EntryRead("URL")
End With
End Function

Once you have the link, you should be able to open it up with ShellExecute.

Later... Karl
 
K

Kalle

Thanks again Karl, but I still can't read the .URL extension, the GetLink is
empty.
Any idea about what to do?

Kalle
 
K

Karl E. Peterson

Kalle said:
Thanks again Karl, but I still can't read the .URL extension, the
GetLink is empty.
Any idea about what to do?

When "stuff" like this happens, about all one can suggest is that you step
through the code, line by line, using the F8 key. Examine each variable at
each step of the way, to determine where things are breaking down. I tested
what I suggested before posting. That method works. The most likely
explanation for your failure is a invalid or poorly-constructed filename.
One test might be to:

* put a breakpoint in the GetLink routine,
* Clipboard.SetText UrlFile,
* Open a command window,
* enter "Dir <Alt-Space, E, P><Enter>"

If you get an empty listing, you got your cause. You could also do a
File-Open in Notepad, and paste the full filename passed to GetLink into
that dialog, to verify you've got it right. Again, if it doesn't open in
Notepad, you need to re-examine how you're deriving the filename.

Later... Karl
--
Working without a .NET?
http://classicvb.org/

 
Top