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 |
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 ... 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 |
Editing Shortcut files
Thanks Steve, that works perfectly.
Fred "Steve Yandl" wrote in message . .. 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 ... 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 |
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 ... Thanks Steve, that works perfectly. Fred "Steve Yandl" wrote in message . .. 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 ... 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 |
All times are GMT +1. The time now is 09:03 AM. |
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com