Add and remove shortcuts in the Open & Save As dialogs

Add and remove shortcuts in the Open & Save As dialogs

Creating and removing customized shortcuts can either be done manually or via code. When we make any change(s) it will affect all Office programs.

Manually
If we want to do it manually we need to open the Regeditor and locate the following key in Windows registry:

HKEY_CURRENT_USER\Software\Microsoft\Office\Versionnumber\Common\Open Find\Places\UserDefinedPlaces

The ‘Versionnumber’ refers to 9.0, 10.0, 11.0 and later.

- Under this key we create a new subkey and name it (for instance Daily Dose)
- For the new subkey we add two string values:
‘Name’ and with the value for the name to be showed in the dialogs (for instance Daily Dose)
‘Path’ and with the value of the pathway to be available in the dialogs (for instance c:\Daily Dose)

The following image shows the settings in the registry:


(The screenshot is from my Swedish Windows XP)

Another important subkey is ‘Places’ which contain the string value ‘ItemSize’. It control if the shortcuts will be showed as compressed (value 0) or not (value 1). If we have many shortcuts it can be suitable to ‘compact’ them in the dialogs. The ‘ItemSize’ can be located at the following place in Windows registry:

HKEY_CURRENT_USER\Software\Microsoft\Office\Versionnumber\Common\Open Find\Places

Via code
The below solutions use the RegObj.dll and for more information about Regobj please see Add-ins - Working with Windows registry

Option Explicit
Option Private Module

'A reference to the Registration Manipulation Classes must be set.

Dim m_regRootKey As RegKey
Dim m_regMainKey As RegKey
Dim m_stSubRoot As String
Dim m_stSubPlace As String

Sub Add_ShortCut_Office()
If Add_ShortCut("11.0", "XL-Dennis", "My storage", "c:\XL-Dennis", 0) Then
    MsgBox "The shortcut has successfully been added to the list.", vbInformation
Else
    MsgBox "The shortcut already exist in Windows Registry.", vbInformation
End If
End Sub

Sub Remove_ShortCut_Office()
If Remove_ShortCut("11.0", "XL-Dennis", 1) Then
    MsgBox "The shortcut has successfully been removed.", vbInformation
Else
    MsgBox "The shortcut does not exist in Windows Registry.", vbInformation
End If
End Sub

Function Add_ShortCut(ByVal stXLVersion, _
                                                   ByVal stMainKey As String, _
                                                   ByVal stName As String, _
                                                   ByVal stPath As String, _
                                                   ByVal lnSize As Long) As Boolean

On Error GoTo Error_Handling

'Registry path to set the size of the shortcuts in the dialogs.
m_stSubPlace = "Software\Microsoft\Office\" & stXLVersion & _
                                  "\Common\Open Find\Places"

'Registry path to add user defined places.
m_stSubRoot = "Software\Microsoft\Office\" & stXLVersion & _
                                 "\Common\Open Find\Places\UserDefinedPlaces"

'Set the rootkey.
Set m_regRootKey = RegKeyFromHKey(HKEY_CURRENT_USER)

'Parse the subkey.
Set m_regMainKey = m_regRootKey.ParseKeyName(m_stSubRoot)

With m_regMainKey
    .SubKeys.Add stMainKey 'Create the subkey.
   With .SubKeys(stMainKey)
        'Add the shortcuts which are string values.
       .Values.Add "Name", stName, RegValueType.rvString
        .Values.Add "Path", stPath, RegValueType.rvString
    End With
End With

'Parse the subkey.
Set m_regMainKey = m_regRootKey.ParseKeyName(m_stSubPlace)

'It seems that there only exist two workable values, 0 and 1
'where 0 represent the compacted status and 1 the standard.
If lnSize > 1 Then
    lnSize = 1
ElseIf lnSize < 0 Then
    lnSize = 0
End If

If m_regMainKey.Values("ItemSize").Value <> lnSize Then
    m_regMainKey.Values("ItemSize").Value = lnSize
End If

Add_ShortCut = True

ExitHere:
'Release objects from memory.
Set m_regRootKey = Nothing
Set m_regMainKey = Nothing
Exit Function

Error_Handling:
    'Error 35004 indicates that the shortcut entry already exist.
   If Err.Number = 35004 Then Add_ShortCut = False
    Resume ExitHere
End Function

Function Remove_ShortCut(ByVal stXLVersion, _
                                                           ByVal stMainKey As String, _
                                                           ByVal lnSize As Long) As Boolean

On Error GoTo Error_Handling

m_stSubPlace = "Software\Microsoft\Office\" & stXLVersion & _
                                  "\Common\Open Find\Places"

m_stSubRoot = "Software\Microsoft\Office\" & stXLVersion & _
                                 "\Common\Open Find\Places\UserDefinedPlaces"

Set m_regRootKey = RegKeyFromHKey(HKEY_CURRENT_USER)

Set m_regMainKey = m_regRootKey.ParseKeyName(m_stSubRoot)

m_regMainKey.SubKeys.Remove stMainKey

Set m_regMainKey = m_regRootKey.ParseKeyName(m_stSubPlace)

If lnSize > 1 Then
    lnSize = 1
ElseIf lnSize < 0 Then
    lnSize = 0
End If

If m_regMainKey.Values("ItemSize").Value <> lnSize Then
    m_regMainKey.Values("ItemSize").Value = lnSize
End If

Remove_ShortCut = True
   
ExitHere:
Set m_regRootKey = Nothing
Set m_regMainKey = Nothing
Exit Function

Error_Handling:
    'Error 35006 indicates that the shortcut entry does not exist.
   If Err.Number = 35006 Then Remove_ShortCut = False
    Resume ExitHere
End Function

The following picture shows the Open Dialog when we have added a shortcut (via the above code) and also have compressed the list:

Shortcuts

For privacy I have removed all info in the dialog

The above is applicable for Excel 2000 and later.

Kind regards,
Dennis

Important: Whenever You are working with the Windows registry make sure You first make a backup of the registry.

10 Comments

  1. Bill Schanks says:

    Very nice tip!

    Any idea’s for getting this across the UI? Like when saving files from IE?

  2. Ivan F Moala says:

    Hi Dennis

    I was actually looking into doing this :) except via APIs.
    Thanks for saving me the time.

  3. Ross says:

    cool tip!, Thanks Dennis

  4. XL-Dennis says:

    Hi guys,

    Bill - I’m not aware of a central part of the registry to control the UI.

    Ivan - Thanks but I would welcome an API solution as this one rely on a separate DLL ;)

    Ross - You’re welcome.

    Kind regards,
    Dennis

  5. Sam says:

    Great tip Dennis,
    Any Ideas on how I can get windows explorer to open in a user defined directory rather than the C:\Documents and Settings\xyz\Start Menu

    Thanks

  6. XL-Dennis says:

    Sam,

    I would suggest that You take a look at Microsoft PowerToys for Windows XP:
    http://www.microsoft.com/windowsxp/downloads/powertoys/xppowertoys.mspx

    The entries in the registry that may be of interest are:
    HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders
    HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders
    (You find similar entries in the HEY_LOCAL_MACHINE part of the registry)

    However, per se I’m not a “registry-hacker” and only solve things when it’s absolutely necessary via the registry ;)

    Kind regards,
    Dennis

  7. Hui... says:

    I use a shortcut with a command line switch in the Quick Launch bar

    eg: C:\WINDOWS\explorer.exe /root, \\Server\directory

    or see

    http://support.microsoft.com/default.aspx?kbid=130510

    Hui…

  8. Sam says:

    Dennis, Hui

    Thanks for the tip…. I forgot I asked the question and saw your reply today

    Regards
    Sam

  9. Dianne Butterworth says:

    In 2003 you can do this by selecting File > Open, then browsing to the desired folder, then going to the Tools menu in the File Open Dialog box and selecting “Add to My Places”.

  10. Sam says:

    Dianne
    Thanks…. had not used that before

    Sam

Leave a Reply