Results 1 to 9 of 9
  1. #1
    2 Star Lounger
    Join Date
    Jun 2002
    Posts
    117
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Shortcut Properties (Access 97)

    Is there a way to access shortcut properties, specifically the Tarket string? I would like to edit the string and save the new string.

    Thanks,

    James

  2. #2
    Bronze Lounger
    Join Date
    Nov 2001
    Location
    Arlington, Virginia, USA
    Posts
    1,394
    Thanks
    0
    Thanked 3 Times in 3 Posts

    Re: Shortcut Properties (Access 97)

    The easiest way to do this is use Windows Script Host (WSH). Simple example:

    Public Sub CreateDesktopShortcut(ByRef strShortcut As String)

    Dim wsh As New IWshRuntimeLibrary.IWshShell_Class
    Dim shrt As New IWshShortcut_Class
    Dim strDesktopPath As String
    Dim strTarget As String

    strDesktopPath = wsh.SpecialFolders("Desktop")
    strTarget = "C:Program FilesMicrosoft OfficeOfficeWINWORD.EXE"

    Set shrt = wsh.CreateShortcut(strDesktopPath & "" & strShortcut & ".lnk")

    With shrt
    .TargetPath = Chr(34) & strTarget & Chr(34)
    .Arguments = Chr(34) & "C:My DocumentsTest.doc" & Chr(34)
    .Hotkey = "CTRL+SHIFT+W"
    .IconLocation = strTarget & ", 0"
    .Description = strShortcut
    .Save
    End With

    Set wsh = Nothing
    Set shrt = Nothing

    End Sub

    You can use WSH CreateShortcut method to create new shortcut, or to modify existing one. Above example worked in either case. Note use of WSH SpecialFolders property to get Desktop path. Also note use of Chr(34) to delimit target path with double-quotes, which are required if any spaces in path. To use this example you need to set a reference to the Windows Script Host Object Model (Ver 1.0) (IWshRuntimeLibrary) (WSHOM.OCX). For more info on WSH properties/methods refer to MSDN reference (look up CreateShortcut under WSH/Reference/Methods):

    Windows Script Host Object Model

    Examples are in VBScript but can be modified for use in VBA.

    HTH

  3. #3
    2 Star Lounger
    Join Date
    Jun 2002
    Posts
    117
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Shortcut Properties (Access 97)

    Thanks

  4. #4
    2 Star Lounger
    Join Date
    Jun 2002
    Posts
    117
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Shortcut Properties (Access 97)

    Thanks again for the example and the information.

    How would I modify the example to capture the current Target of a shortcut? I want to test for a string before I modify it.

    Thanks

  5. #5
    2 Star Lounger
    Join Date
    Jun 2002
    Posts
    117
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Shortcut Properties (Access 97)

    I can get part of the Target of the shortcut with the following:

    Set shrt = wsh.CreateShortcut(strDesktopPath)

    strTarket = shrt.TargetPath

    shrt.TargetPath is returning everything within the first set of quotes. Any ideas on how to capture the MDB and MDW information which are inclosed in quotes of their own?

  6. #6
    2 Star Lounger
    Join Date
    Jun 2002
    Posts
    117
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Shortcut Properties (Access 97)

    Got it!

  7. #7
    Bronze Lounger
    Join Date
    Nov 2001
    Location
    Arlington, Virginia, USA
    Posts
    1,394
    Thanks
    0
    Thanked 3 Times in 3 Posts

    Re: Shortcut Properties (Access 97)

    As you probably figured out, the shortcut Arguments property will contain any command line arguments, such as path to workgroup file, that follow TargetPath. Example of how you can retrieve these properties with existing shortcut, for anyone interested:

    Public Sub GetShortcutProperties(ByRef strShortcut As String)
    On Error GoTo Err_Handler

    Dim wsh As New IWshRuntimeLibrary.IWshShell_Class
    Dim lnk As New IWshShortcut_Class
    Dim fso As New IWshRuntimeLibrary.FileSystemObject
    Dim strDesktopPath As String
    Dim strTarget As String
    Dim strArgs As String
    Dim strMsg As String

    strDesktopPath = wsh.SpecialFolders("Desktop")

    If fso.FileExists(strDesktopPath & "" & strShortcut & ".lnk") Then
    Set lnk = wsh.CreateShortcut(strDesktopPath & "" & strShortcut & ".lnk")
    ' Get shortcut properties:
    strTarget = lnk.TargetPath
    strArgs = lnk.Arguments
    Debug.Print "Target: " & strTarget
    Debug.Print "Arguments: " & strArgs
    ' Change properties if necessary, then save
    Else
    strMsg = "Shortcut not found."
    MsgBox strMsg, vbExclamation, "NOT FOUND"
    ' Create new shortcut here if necessary, then save
    End If

    Exit_Sub:
    Set wsh = Nothing
    Set lnk = Nothing
    Set fso = Nothing
    Exit Sub
    Err_Handler:
    Select Case Err.Number
    Case 0
    Resume Next
    Case Else
    strMsg = "Error No " & Err.Number & ": " & Err.Description
    MsgBox strMsg, vbExclamation, "SHORTCUT ERROR"
    Resume Exit_Sub
    End Select

    End Sub

    Example of use:

    GetShortcutProperties "Shortcut to Northwind"
    Target: C:Program FilesMicrosoft OfficeOffice10MSACCESS.EXE
    Arguments: "C:Program FilesMicrosoft OfficeOffice10SamplesNorthwind.mdb"

    Note that the Arguments property included the quotes, but not the TargetPath. (I used Chr(34) for both when creating shortcut.) But in any event you can test shortcut properties & modify if necessary by using WSH.

    HTH

  8. #8
    2 Star Lounger
    Join Date
    Jun 2002
    Posts
    117
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Shortcut Properties (Access 97)

    Thanks again!

  9. #9
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Shortcut Properties (Access 97)

    Here's something I dropped on, perhaps you can do something woth it for your purpose.
    Attached Files Attached Files

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •