creating a desktop shortcut icon via VBA

  • Thread starter Thread starter Virgil
  • Start date Start date
V

Virgil

Is it possible to create a desktop shortcut icon via VBA?
There's nothing on the subject in the AccessWeb APIs.
 
Not directly, but you can use Windows Script Host through VBA:

Dim objWshShell As Object
Dim objWshShortcut As Object
Dim strProgLocn As String
Dim strDBLocn As String
Dim strDBPath As String
Dim strDesktop As String

Set objWshShell = CreateObject("WScript.Shell")

strDesktop = objWshShell.SpecialFolders("Desktop")
strProgLocn = SysCmd(acSysCmdAccessDir) & "msaccess.exe"
strDBLocn = CurrentDb.Name
strDBPath = Left$(strDBLocn, Len(strDBLocn) - Len(Dir$(strDBLocn)))

Set objWshShortcut = objWshShell.CreateShort( _
strDesktop & "\My Shortcut.lnk")

With objWshShortcut
.TargetPath = strProgLocn
.Arguments = Chr$(34) & strDBLocn & Chr$(34)
.WorkingDirectory = strDBPath
.WindowStyle = 4
.Save
End With

Set objWshShortcut = Nothing
Set objWshShell = Nothing

Take a look at
http://msdn.microsoft.com/library/en-us/script56/html/wsmthcreateshortcut.as
p for more details.
 
Back
Top