VBA TIPS
Making a short cut icon on the desktop

Here is an example procedure to make a short cut icon on your desktop with WSH (Windows Scripting Host).

From Microsoft website
Windows Script Host (WSH) is a Windows administration tool.
WSH creates an environment for hosting scripts. That is, when a script arrives at your computer, WSH plays the part of the host ? it makes objects and services available for the script and provides a set of guidelines within which the script is executed. Among other things, Windows Script Host manages security and invokes the appropriate script engine.

WSH is language-independent for WSH-compliant scripting engines. It brings simple, powerful, and flexible scripting to the Windows platform, allowing you to run scripts from both the Windows desktop and the command prompt. Windows Script Host is ideal for noninteractive scripting needs, such as logon scripting, administrative scripting, and machine automation.

read more details:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/script56/html/wsconwhatiswsh.asp

It sounds something difficult stuff, but take it easy. With WSH, you can do a lot of things that cannot be done with Excel alone.
For example, SpecialFolders Method of the Shell object gives you the location of the Windows desktop for the current user. And you can create a shortcut icon using CreateShortcut method of the Shell method.



You can use the appropreate icon by changing the path of IconLocation and you can change Hotkey.

Sub MakeShortcut() is an example for using Early binding, Sub MakeShortcut2() is an example for using Late binding,.

With regards to Early vs. Late Binding, here is a nice TIP written by Dave Rado(MS Word MVP). http://word.mvps.org/FAQs/InterDev/EarlyvsLateBinding.htm

Place the following in the standard module.

Option Explicit

Sub MakeShortcut()
'//Need to refer to Windows Script Host Object Module
    Dim WSH As New IWshRuntimeLibrary.IWshShell_Class
    Dim WSHShortcut As IWshRuntimeLibrary.IWshShortcut_Class
    Dim strPath As String

    strPath = WSH.SpecialFolders("Desktop") & "\" & "notepad.lnk"
    Set WSHShortcut = WSH.CreateShortcut(strPath)
    With WSHShortcut
        .TargetPath = Environ("WINDIR") & "\" & "notepad.exe"
        .Description = "make shortcut to notepad"
        .IconLocation = "c:\windows\system\shell32.dll,5"
        .RelativePath = "c:\temp"
        .WorkingDirectory = "c:\"
        .Hotkey = "Ctrl+Alt+Q"
        .Save
    End With
End Sub

'Or you can write as follows.

Sub MakeShortcut2()
    Dim WSH As Object
    Dim WSHShortcut As Object
    Dim strPath As String
    Set WSH = CreateObject("WScript.Shell")

    strPath = WSH.SpecialFolders("Desktop") & "\" & "notepad.lnk"
    Set WSHShortcut = WSH.CreateShortcut(strPath)
    With WSHShortcut
        .TargetPath = Environ("WINDIR") & "\" & "notepad.exe"
        .Description = "make shortcut to notepad"
        .IconLocation = "c:\windows\system\shell32.dll,5"
        .RelativePath = "c:\temp"
        .WorkingDirectory = "c:\"
        .Hotkey = "Ctrl+Alt+Q"
        .Save
    End With
End Sub



| HOME |
Copyright © cellmasters.net - colo's junk room All Right Reserved
ABOUT
WORKS
THE CELL MASTERS
CONTACT
LINKS
Tips and Information about Microsoft Excel|Masaru Kaji aka Colo