Results 1 to 2 of 2

VBA create short cut

  1. #1
    M.Enders is offline Novice
    Windows 7 64bit Access 2013 64bit
    Join Date
    Jun 2017

    VBA create short cut

    Good evening all,

    I have basic VBA to edit an external word document once the edits are made the file saves into a filing system:

    wDoc.SaveAs2 ("C:\Supply_Excellence" & (RS!SLOC) & "_" & (RS!SLOCName) & "" & (RS!SLOC) & "_SHR_Initial_Counseling_" & Format(Now(), "yyyymmdd") & "_" & (RS!LastName) & ".doc")

    I would then like to create a shortcut to the file on the desktop, but I simply do not know how to.

    Was hoping someone has created a shortcut using VBA that can show me.

    Thank you,


  2. #2
    GinaWhipp's Avatar
    GinaWhipp is offline Competent Performer
    Windows 7 64bit Access 2013 32bit
    Join Date
    Jul 2011
    Ohio, USA

    Function fncCreateShortcut(strPathFile, strShortcutName) As String
    '11.23.2012 Crystal Long
    '4.2.2018 Gina Whipp (Access Diva) changed to a Function and removed hardcoding
    ' for early binding -- needs reference to Windows Script Host Object Module
    'this code uses late binding so no reference is necessary
    On Error GoTo Proc_Err
        Dim oWsh As Object
        Dim oShortcut As Object
        Dim strPathDesktop As String
        Dim sShortcut As String
        Set oWsh = CreateObject("WScript.Shell")
        strPathDesktop = oWsh.SpecialFolders("Desktop")
        sShortcut = strPathDesktop & "\" & strShortcutName & ".lnk"
        Set oShortcut = oWsh.CreateShortcut(sShortcut)
            With oShortcut
               .TargetPath = strPathFile
               '.Description = "Description of icon"
               '.RelativePath = "C:\temp"
               '.WorkingDirectory = "M:\"
               '.IconLocation = "F:\Code11\test.ico"
            End With
        MsgBox "Shortcut created!"
          On Error Resume Next
          Set oShortcut = Nothing
          Set oWsh = Nothing
          Exit Function
       MsgBox Err.Description, , "ERROR " & Err.Number & "   CreateShortcut "
       Resume Proc_Exit
    End Function
    Gina Whipp
    Microsoft MVP (Access 2010-2015)

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 5
    Last Post: 08-10-2018, 01:20 PM
  2. Can't access the database with short cut
    By Jopaha in forum Access
    Replies: 2
    Last Post: 03-13-2017, 12:46 PM
  3. Short Interval Control
    By Puggwash in forum Access
    Replies: 2
    Last Post: 12-30-2016, 01:14 PM
  4. Short date comparison
    By andy101 in forum Programming
    Replies: 2
    Last Post: 03-17-2011, 03:36 AM
  5. CTRL +' Short Cut Key
    By desireemm1 in forum Access
    Replies: 2
    Last Post: 09-10-2009, 02:25 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
Tech Forums: Microsoft Office Forums