Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can I create a shortcut using VBA

Status
Not open for further replies.

wtstro

Programmer
Aug 1, 2002
15
US
I have an MS-Access application that uses a workgroup. Using VBA, I want the user to click on a button that will create a shortcut to the application with the /wrkgrp parameter added to the target string (example: D:\MyProgram\MyAccessApp.mdb /wrkgrp d:\MyProgram\MyAccessSecurity.mdw)
[sadeyes] I have been looking for almost a week now. Can anyone help me???
 
Thank you junior1544 for your suggestion. I tried something very similar but it won't let me add parameters to it.

Thanks to dsi [thumbsup2] for the suggestion that steered me to this solution [wiggle] :

Option Explicit

Public Declare Function fCreateShellLink Lib "Vb5stkit.dll" (ByVal _
lpstrFolderName As String, ByVal lpstrLinkName As String, ByVal _
lpstrLinkPath As String, ByVal lpstrLinkArgs As String) As Long


Sub DoShortcut()
Dim lReturn As Long
Dim DestPath As String
Dim LinkArg As String
Dim ShortcutName As String
Dim AppPath As String

AppPath = "D:\Program Files\TSMN\"
DestPath = "C:\Program Files\Microsoft Office\Office\MSAccess.EXE"
LinkArg = " " & Chr(34) & AppPath & "TSMN.mdb" & Chr(34) & " /wrkgrp " & Chr(34) & AppPath & "TSMNSys.mdw" & Chr(34)
ShortcutName = "Shortcut to TSMN"

'Add shortcut to desktop
lReturn = fCreateShellLink("..\..\Desktop", ShortcutName, DestPath, LinkArg)
If lReturn = 0 Then
Beep
MsgBox "Error while creating Desktop shortcut for: " & ShortcutName & ".", vbCritical + vbOKOnly, "Create Error"
End If

'Add shortcut to Program Menu Group
lReturn = fCreateShellLink("", ShortcutName, DestPath, LinkArg)
If lReturn = 0 Then
Beep
MsgBox "Error while creating Program Menu Group shortcut for: " & ShortcutName & ".", vbCritical + vbOKOnly, "Create Error"
End If

'Add shortcut to Startup Group
'Note that on Windows NT, the shortcut will not actually appear in the Startup group until your next reboot.
lReturn = fCreateShellLink("\Startup", ShortcutName, DestPath, LinkArg)
If lReturn = 0 Then
Beep
MsgBox "Error while creating Startup Group shortcut for: " & ShortcutName & ".", vbCritical + vbOKOnly, "Create Error"
End If

End Sub


Call DoShortcut() from your code. It was important to set up the LinkArg variable using the Chr(34) in order to account for spaces within a folder name.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top