Results 1 to 5 of 5
  1. #1
    3 Star Lounger
    Join Date
    Feb 2003
    Posts
    363
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Creating a Desktop Shortcut (xl2000)

    I have saved a file to a new folder and would now like to create a shortcut to that file and place it on the desktop.

    My search thru the VBE help section reveals the following that might be combined in a way to do this:

    CommandBarButton (Type:= msoCommandBarButtonHyperlinkInsertPicture)
    CommandBarButton(Type:=msoCommandBarButtonOpen)
    CommandBarButton.ShortcutText = "MyText"
    CommandBarButton.Move

    I have an icon file that I would use for the "Picture" ----- "MyIcon.ico"

    Is anyone familiar with doing this from within excel?
    How would I "ADD" a commandBarButton to a file? Then assign the Icon picture Then save the Icon the Desktop?

    Thanks

  2. #2
    Platinum Lounger
    Join Date
    Nov 2001
    Location
    Vienna, Wien, Austria
    Posts
    5,009
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Creating a Desktop Shortcut (xl2000)

    Right click on the file, choose Create Shortcut and then drag and drop the Shortcut onto your Desktop.

    Is there something else you're trying to do as well?
    Gre

  3. #3
    3 Star Lounger
    Join Date
    Feb 2003
    Posts
    363
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Creating a Desktop Shortcut (xl2000)

    Thanks for the quick reply

    Your described method is a "Manual" method that requires leaving xl.

    What I am trying to do is automate this with VBA from within xl

  4. #4
    3 Star Lounger Jim Cone's Avatar
    Join Date
    Feb 2002
    Location
    Portland, Oregon, USA
    Posts
    238
    Thanks
    0
    Thanked 3 Times in 3 Posts

    Re: Creating a Desktop Shortcut (xl2000)

    Paul,

    The following code works for me...
    '-----------------------------------------------
    'May require a reference to the Microsoft Scripting Runtime (scrrun.dll).
    'Windows Script Host is provided with most versions of Windows.

    Sub Desktopshortcut()
    Dim WSHShell As Object
    Dim MyShortcut As Object
    Dim DesktopPath As String

    Set WSHShell = CreateObject("WScript.Shell")
    DesktopPath = WSHShell.SpecialFolders("Desktop")
    Set MyShortcut = WSHShell.CreateShortcut(DesktopPath & "" & ActiveWorkbook.Name & ".lnk")
    'Set MyShortcut = WSHShell.CreateShortcut(DesktopPath & "TestFile.lnk") 'another way

    With MyShortcut
    .TargetPath = ActiveWorkbook.FullName
    '.TargetPath = "Cocuments and Settings......TestFile.xls" 'another way
    .WindowStyle = 1
    .IconLocation = "F:IconsArrowsARW03LT.ICO"
    .Save
    End With

    Set MyShortcut = Nothing
    Set WSHShell = Nothing
    MsgBox "A shortcut has been placed on your desktop. ", vbInformation, "Primitive Software"
    End Sub
    '--------------------------------------------------------
    Adjust the file path / locations as needed.

    Regards,
    Jim Cone
    San Francisco, CA

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

    Re: Creating a Desktop Shortcut (xl2000)

    If you are allowed to use Scripting, you can use the following (added: only a small variation on Jim Cone's code)

    Select Tools | References...
    Locate Windows Script Host Object Model in the list, and check the corresponding box.
    Click OK.

    Here is a macro that creates a shortcut on the desktop. I will leave it up to you to finetune it:

    Sub MakeShortcut(strName As String, strTarget As String, strIcon As String)
    Dim wsh As New IWshRuntimeLibrary.WshShell
    Dim shc As IWshRuntimeLibrary.WshShortcut
    Dim strDesktop As String
    strDesktop = wsh.SpecialFolders.Item("Desktop")
    Set shc = wsh.CreateShortcut(strDesktop & "" & strName & ".lnk")
    With shc
    .TargetPath = strTarget
    .IconLocation = strIcon
    .Save
    End With
    Set shc = Nothing
    Set wsh = Nothing
    End Sub

    Call it like this:

    MakeShortcut "Click Me", "C:ExcelMyWorkbook.xls", "C:ExcelMyIcon.ico"

Posting Permissions

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