Link to home
Start Free TrialLog in
Avatar of Stephen_Perrett
Stephen_Perrett

asked on

Create Windows shortcut using VBA with /WrkGrp switch

I am trying to create a windows shortcut using VBA with the following code

On Error Resume Next
    Dim wsShell As New WshShell
    Dim wsSCut As WshShortcut
    Dim strCommandLine As String 'Command Line for shortcut to run
    strCommandLine = Chr(34) & "C:\Program Files\Microsoft Office\OFFICE11\MSACCESS.EXE" & Chr(34)
    strCommandLine = strCommandLine & " /WrkGrp " & Chr(34) & "C:\Security.mdw" & Chr(34)
    strCommandLine = strCommandLine & " " & Chr(34) & "C:\MyDb.mdb" & Chr(34)
    Set wsSCut = wsShell.CreateShortcut("C:\ShortcutToMyDB.lnk")
    With wsSCut
        .TargetPath = strCommandLine
        .Save
    End With
   
    Set wsSCut = Nothing
    Set wsShell = Nothing
End Sub

The problem is that the

/WrkGrp

switch gets converted to \WrkGrp causing the resultant shortcut to fail.

Is there any way to crate a shortcut with the /WrkGrp switch in tact using VBA ?
Avatar of nico5038
nico5038
Flag of Netherlands image

Did you try:
    strCommandLine = Chr(34) & "C:\Program Files\Microsoft Office\OFFICE11\MSACCESS.EXE"
    strCommandLine = strCommandLine & " /WrkGrp " & Chr(34) & "C:\Security.mdw" & Chr(34)
Leaving out the CHR(34) after the .exe ?

Nic;o)

Oops, then a space needs to be added:
    strCommandLine = Chr(34) & "C:\Program Files\Microsoft Office\OFFICE11\MSACCESS.EXE"
    strCommandLine = strCommandLine & " /WrkGrp " & Chr(34) & " " & Chr(34) & "C:\Security.mdw" & Chr(34)

Nic;o)
Avatar of Stephen_Perrett
Stephen_Perrett

ASKER

Nico thanks but your suggestion doesn't work either

My original code gives me the correct command line string
with debug.print
which works if pasted into the shortcut.
 
It seems that Windows (XP at least) converts forward slashes to backward slashes

Do you know if a command line shortcut is possible to produce using VBA?
For that the SHELL command can be used.

Nic;o)
ASKER CERTIFIED SOLUTION
Avatar of nico5038
nico5038
Flag of Netherlands image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks Nico

That works really well!

Steve
Glad I could help (and learn a new trick myself:-)

Success !

Nic;o)