Results 1 to 3 of 3
  1. #1
    5 Star Lounger
    Join Date
    Apr 2003
    Location
    Hampshire, United Kingdom
    Posts
    602
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Creating File Shortcuts (VBA: Office XP)

    I know how to copy actual files from one folder to another, but I'd like to put shortcuts in my destination folder instead of actual copies. Any ideas on how to do this? <img src=/S/confused.gif border=0 alt=confused width=15 height=20>

    Many thanks <img src=/S/cheers.gif border=0 alt=cheers width=30 height=16>
    Waggers
    If at first you do succeed, you&#39;ve probably missed something.

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Creating File Shortcuts (VBA: Office XP)

    Here is a general procedure to create a shortcut:

    Sub CreateAShortcut _
    (FileName As String, _
    Target As String, _
    Optional WorkingDirectory As String, _
    Optional WindowStyle As Integer = vbNormalFocus, _
    Optional Description As String)

    With CreateObject("WScript.Shell").CreateShortcut(FileN ame)
    .TargetPath = Target
    .WindowStyle = WindowStyle
    .Description = Description
    .WorkingDirectory = WorkingDirectory
    .Save
    End With
    End Sub

    The procedure has 5 arguments, of which the first two are required.
    <UL><LI>FileName: the path and name of the shortcut to be created; the name must have extension .lnk if it is a shortcut to a file, .url if it is a shortcut to a web address.
    <LI>Target: what the shortcut refers to.
    <LI>WorkingDirectory: the name of the folder to work in.
    <LI>WindowStyle: how should the shortcut be opened: possible values are vbHide, vbNormalFocus (default), vbMinimizedFocus, vbMaximizedFocus, vbNormalNoFocus, vbMinimizedNoFocus, vbMaximizedNoFocus.
    <LI>Description: text for the tooltip you see when hovering the mouse pointer over the shortcut.[/list]Call it like this:

    <code>CreateAShortcut "F:GeneralMyDatabase.lnk", "F:AccessTest.mdb", , vbMaximizedFocus</code>

    or

    <code>CreateAShortcut FileName:=""F:GeneralMyDatabase.lnk", Target:="F:AccessTest.mdb", _</code>
    <code> Description:="Link to test database"</code>

  3. #3
    5 Star Lounger
    Join Date
    Apr 2003
    Location
    Hampshire, United Kingdom
    Posts
    602
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Creating File Shortcuts (VBA: Office XP)

    Hans, you're a genius! Many thanks. <img src=/S/clapping.gif border=0 alt=clapping width=19 height=23>
    Waggers
    If at first you do succeed, you&#39;ve probably missed something.

Posting Permissions

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