#1
|
|||
|
|||
Outlook VBA macro runs from editor, but not from Outlook ribbon?
I have a macro I made to create a new directory and move the selected message into it. It works fine if I run it from the VBA editor, but when I try to run it from Outlook using a button on the ribbon, nothing happens.
I have Macro Security set to "Enable all macros", at least for testing. Code:
Sub MakeNewPIFolderAndMoveEmail() Dim objOutlook As Outlook.Application Dim myItems As Outlook.Items Dim fldRoot As Outlook.MAPIFolder Dim fldPIs As Outlook.MAPIFolder, fldNew As Outlook.MAPIFolder Dim strFolderName As String Dim Explorer Dim CurrentItem Set objOutlook = CreateObject("outlook.application") ' from the default inbox to the parent which is your mailbox Set fldRoot = objOutlook.GetNamespace("MAPI").GetDefaultFolder(olFolderInbox).Parent ' from the mailbox to a folder at the same level as the Inbox Set fldPIs = fldRoot.Folders("PIs") strFolderName = InputBox("Enter name for the PI folder", "Folder Name") If Len(strFolderName) = 0 Then Exit Sub End If Set fldNew = fldPIs.Folders.Add(strFolderName) Set Explorer = Application.ActiveExplorer ' Check whether any item is selected in the current folder. If Explorer.Selection.Count Then ' Get the first selected item. Set CurrentItem = Explorer.Selection(1) If CurrentItem.Class = olMail Then CurrentItem.Move fldNew End If End If End Sub |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
vba Option remove Editor from Ribbon | jec1 | Word | 10 | 12-08-2021 11:19 PM |
Add a slide library to a custom ribbon with RibbonX Editor | tompen78 | PowerPoint | 0 | 07-07-2021 12:19 AM |
Size of Outlook Ribbon Changes When Ribbon Is Pinned | man_utd_fan | Outlook | 5 | 03-24-2021 03:08 AM |
pros & cons of Word as editor in Outlook 2003 | bolandg | Outlook | 0 | 11-21-2009 08:02 PM |
Outlook 2002 locks up with Word as Editor when replying to s | Larry S | Outlook | 6 | 12-12-2005 07:18 AM |