|
|
|
|
|
|
Excel
|
Create a Custom Desktop Shortcut
|
|
Ease of Use
|
Easy
|
Version tested with
|
2000, 2002, 2003
|
Submitted by:
|
Justinlabenne
|
Description:
|
Uses an Icon file for a shortcut in place of the standard "Workbook" icon.
The example provided contains an Excel file, and an .ico (icon) file.
|
Discussion:
|
If you design your projects in such a way that Excel's environment is customized extensively (IE: Application Icon, Hidden toolbars / command bars, etc..) this code allows you to use a custom icon (.ico file) to create a desktop shortcut back to your Excel workbook.
|
Code:
|
instructions for use
|
Option Explicit
Sub CreateDesktopShortcut()
Dim szMsg As String
Dim szStyle As String
Dim szTitle As String
Const szIconName As String = "\cvg.ico"
Const szlocation As String = "Desktop"
Const szLinkExt As String = ".lnk"
Dim oWsh As Object
Dim oShortcut As Object
Dim szSep As String
Dim szBookName As String
Dim szBookFullName As String
Dim szPath As String
Dim szDesktopPath As String
Dim szShortcut As String
szSep = Application.PathSeparator
szBookName = szSep & ThisWorkbook.Name
szBookFullName = ThisWorkbook.FullName
szPath = ThisWorkbook.Path
On Error GoTo ErrHandle
Set oWsh = CreateObject("WScript.Shell")
szDesktopPath = oWsh.SpecialFolders(szlocation)
szShortcut = szDesktopPath & szBookName & szLinkExt
Set oShortcut = oWsh.CreateShortCut(szShortcut)
With oShortcut
.TargetPath = szBookFullName
.IconLocation = szPath & szIconName
.Save
End With
Set oWsh = Nothing
Set oShortcut = Nothing
szMsg = "Shortcut was created successfully"
szStyle = 0
szTitle = "Success!"
MsgBox szMsg, szStyle, szTitle
Exit Sub
ErrHandle:
szMsg = "Shortcut could not be created"
szStyle = 48
szTitle = "Error!"
MsgBox szMsg, szStyle, szTitle
End Sub
|
How to use:
|
- Open an Excel Workbook
- Copy the code
- Press Alt + F11 to open the Visual Basic Editor (VBE)
- Select INSERT > MODULE from the menubar
- Paste code into the right pane
- Press Alt+Q to return to Excel
- Save workbook before any other changes
|
Test the code:
|
- Go to TOOLS > MACRO > MACROS >
- When the dialog appears, select {CreateDesktopShortcut}
- Press {Run}
- You will be prompted if the shortcut was created successfully or not
- If it was, close the Excel file
- Use the newly created desktop shortcut to re-open the Excel file that contains the code
|
Sample File:
|
Create S-Cut.zip 15.44KB
|
Approved by mdmackillop
|
This entry has been viewed 312 times.
|
|