Closed Thread
Results 1 to 4 of 4

Editing Shortcut files

  1. #1
    Fred
    Guest

    Editing Shortcut files

    Does anyone know how I can create and edit a shortcut file in VB.
    I am trying to create a shortcut to a workbook and then edit the 'start in:'
    field of the shortcut

    Thanks
    Fred



  2. #2
    Steve Yandl
    Guest

    Re: Editing Shortcut files

    The following example using the WScript shell object creates a shortcut to
    the workbook the macro is in and sets the 'Start In' (working directory) to
    C:\Scripts.

    ____________________________________________

    strWkbkTgt = ThisWorkbook.Path & "\" & ThisWorkbook.Name

    Set objWSH = CreateObject("WScript.Shell")
    strDesktop = objWSH.SpecialFolders("Desktop")

    Set objLink = objWSH.CreateShortcut(strDesktop & "\" & ThisWorkbook.Name &
    ".lnk")
    objLink.TargetPath = strWkbkTgt
    objLink.WorkingDirectory = "C:\Scripts"
    objLink.Save

    ______________________________________________

    Steve



    "Fred" <leavemealone@home> wrote in message
    news:[email protected]...
    > Does anyone know how I can create and edit a shortcut file in VB.
    > I am trying to create a shortcut to a workbook and then edit the 'start
    > in:' field of the shortcut
    >
    > Thanks
    > Fred
    >
    >




  3. #3
    Fred
    Guest

    Re: Editing Shortcut files

    Thanks Steve, that works perfectly.

    Fred

    "Steve Yandl" <[email protected]> wrote in message
    news:[email protected]...
    > The following example using the WScript shell object creates a shortcut to
    > the workbook the macro is in and sets the 'Start In' (working directory)
    > to C:\Scripts.
    >
    > ____________________________________________
    >
    > strWkbkTgt = ThisWorkbook.Path & "\" & ThisWorkbook.Name
    >
    > Set objWSH = CreateObject("WScript.Shell")
    > strDesktop = objWSH.SpecialFolders("Desktop")
    >
    > Set objLink = objWSH.CreateShortcut(strDesktop & "\" & ThisWorkbook.Name &
    > ".lnk")
    > objLink.TargetPath = strWkbkTgt
    > objLink.WorkingDirectory = "C:\Scripts"
    > objLink.Save
    >
    > ______________________________________________
    >
    > Steve
    >
    >
    >
    > "Fred" <leavemealone@home> wrote in message
    > news:[email protected]...
    >> Does anyone know how I can create and edit a shortcut file in VB.
    >> I am trying to create a shortcut to a workbook and then edit the 'start
    >> in:' field of the shortcut
    >>
    >> Thanks
    >> Fred
    >>
    >>

    >
    >




  4. #4
    Steve Yandl
    Guest

    Re: Editing Shortcut files

    You're welcome. The object also lets you set WindowStyle, HotKey, and
    IconLocation (icon choice) for the shortcut but I've never found any of them
    important enough to include in routines I write.

    Steve



    "Fred" <leavemealone@home> wrote in message
    news:e%[email protected]...
    > Thanks Steve, that works perfectly.
    >
    > Fred
    >
    > "Steve Yandl" <[email protected]> wrote in message
    > news:[email protected]...
    >> The following example using the WScript shell object creates a shortcut
    >> to the workbook the macro is in and sets the 'Start In' (working
    >> directory) to C:\Scripts.
    >>
    >> ____________________________________________
    >>
    >> strWkbkTgt = ThisWorkbook.Path & "\" & ThisWorkbook.Name
    >>
    >> Set objWSH = CreateObject("WScript.Shell")
    >> strDesktop = objWSH.SpecialFolders("Desktop")
    >>
    >> Set objLink = objWSH.CreateShortcut(strDesktop & "\" & ThisWorkbook.Name
    >> & ".lnk")
    >> objLink.TargetPath = strWkbkTgt
    >> objLink.WorkingDirectory = "C:\Scripts"
    >> objLink.Save
    >>
    >> ______________________________________________
    >>
    >> Steve
    >>
    >>
    >>
    >> "Fred" <leavemealone@home> wrote in message
    >> news:[email protected]...
    >>> Does anyone know how I can create and edit a shortcut file in VB.
    >>> I am trying to create a shortcut to a workbook and then edit the 'start
    >>> in:' field of the shortcut
    >>>
    >>> Thanks
    >>> Fred
    >>>
    >>>

    >>
    >>

    >
    >




Closed Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1