Remove OutlookBarShortcut

D

dorutzu

Hi,

I'm trying to programatically remove a shortcut to a folder from the
OutlookBar. The problem is that I get a "Run-time error 13: Type
mismatch" message when I try to run my code.

Sub test5()
Dim myOlBar As OutlookBarPane
Set myOlBar = Application.ActiveExplorer.Panes.Item("OutlookBar")
myOlBar.Contents.Groups.Item(1).Shortcuts.Remove ("ShortcutName")
End Sub

Also, I know for a fact that this shortcut exist - here is the code
again, modified a bit:

Sub test5()
Dim myOlBar As OutlookBarPane
Set myOlBar = Application.ActiveExplorer.Panes.Item("OutlookBar")
Set mySh = myOlBar.Contents.Groups.Item(1).Shortcuts.Item("ShortcutName")
'see if I got what I needed...
MsgBox mySh.Name 'indeed, "ShortcutName" appears in the messagebox
'now try to remove the shortcut with this EXACT name
myOlBar.Contents.Groups.Item(1).Shortcuts.Remove (mySh.Name) 'I get
the type mismatch error here :((
End Sub

The idea is that Remove does not work with the name of the shortcut
(apparently), only with it's index. Any idea how can I get the index
of my shortcut instead (except for iterating trough Shortcuts)?

Thanks,
Doru
 
S

Sue Mosher [MVP-Outlook]

Loop through the Shortcuts collection checking the name of each item, then remove the one that matches:

Set scuts = myOlBar.Contents.Groups.Item(1).Shortcuts
For i = 1 to scuts.Count
If scuts(i).Name = "ShortcutName"
scuts.Remove i
Exit For
End If
Next
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top