none
Outlook Macro Button Not Working

    Question

  • Hi All

    I have a macro that places a "copy" of an email into a separate folder when it is run. The macro works fine 100% of the time when it is run manually. However when I attach the macro to a button on a toolbar it runs for a short while then fails to run at all.

    I am using Outlook 2016 on Windows 7.

    I have tried to replace the button numerous times to re-set it but to no avail.

    Has anyone else had this issue and if so how did you resolve it.

    Any help/advice would be appreciated.

    Kind regards

    Tony


    TKHussar

    Tuesday, March 21, 2017 11:23 AM

Answers

  • Hi Winnie

    Many thanks for your response.  The details are :

    Microsoft Outlook 2013 (15.0.4893.1000) MSO (15.0.4893.1000) 32 bit

    Product ID: 00218-02490-20695-AA703

    The macro code we are using is as follows:

    Sub MoJCopyTo2HrFolder()
    On Error Resume Next
    'MsgBox ("This is the move to 2 Hour Folder function")
    Dim ns As Outlook.NameSpace
    Dim moveToFolder As Outlook.MAPIFolder
    Dim objItem As Outlook.mailItem
    
    MsgBox ("I am in the MoJ 2Hour Macro")
    Set ns = Application.GetNamespace("MAPI")
    
    'Define path to the target folder
    Set moveToFolder = ns.Folders("_SSG Support_SSCL.MOJ.PMO").Folders("Two Hour Mails MOJ")
    
    If Application.ActiveExplorer.Selection.Count = 0 Then
       MsgBox ("No item selected")
       Exit Sub
    End If
    
    If moveToFolder Is Nothing Then
       MsgBox "Target folder not found!", vbOKOnly + vbExclamation, "Move Macro Error"
    End If
    For Each objItem In Application.ActiveExplorer.Selection
       If moveToFolder.DefaultItemType = olMailItem Then
          If objItem.Class = olMail Then
             Set objItem = objItem.Copy
             objItem.Move moveToFolder
          End If
      End If
    Next
    
    Set objItem = Nothing
    Set moveToFolder = Nothing
    Set ns = Nothing
    
    End Sub

    Thanks

    Tony



    TKHussar

    • Marked as answer by TKHussar Tuesday, June 19, 2018 10:46 AM
    Wednesday, April 12, 2017 2:30 PM

All replies

  • Hi All

    I have a macro that places a "copy" of an email into a separate folder when it is run. The macro works fine 100% of the time when it is run manually. However when I attach the macro to a button on a toolbar it runs for a short while then fails to run at all.

    I have tried to replace the button numerous times to re-set it but to no avail.

    Has anyone else had this issue and if so how did you resolve it.

    Any help/advice would be appreciated.

    Kind regards

    Tony

    TKHussar

    Monday, March 20, 2017 2:17 PM
  • Hello Tony,

    Did you try to debug the code? Is there any error in the code?

    Are macros allowed to run all the time in Outlook?

    Take a look at the following articles:

    Troubleshooting Outlook VBA

    OUTLOOK MACRO STOPS WORKING (OR DOESN’T WORK TO BEGIN WITH)?


    profile for Eugene Astafiev at Stack Overflow, Q&A for professional and enthusiast programmers


    Monday, March 20, 2017 3:24 PM
  • Hi Eugene

    It works perfectly every time when I select the macro from the Developer tab.  It just won't work when I attach the macro to a button on a toolbar!

    Thanks

    Tony


    TKHussar

    Monday, March 20, 2017 5:21 PM
  • Hi Tony,

    I suggest you create a simple macro like to display a message box to check if the issue is reproducible.

    According to your description, I think it is not a programing issue. I would move this thread into Outlook IT Pro Discussions forum for further troubleshooting. And I suggest you share your detail version number here to check if the issue is related to certain version.

    Regards,

    Celeste


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, March 21, 2017 2:42 AM
  • Hi  Celeste

    Many thanks for your response.  It is definitely not a macro issue as it works every time when I select it from the Developer Tab.  It works the first couple of ties then stops working.

    I will try and post it on the Outlook IT Pro Discussions forum as you suggest.

    Many thanks

    Kind regards

    Tony


    TKHussar

    Tuesday, March 21, 2017 11:21 AM
  • Hi Tony,

    What's your detailed Outlook 2016 version? Please click File > Account > About Outlook to collect the detailed version number.

    If possible, could you please provide your Macro codes here so that we can follow your steps and do further test on our Outlook environment?


    Regards,

    Winnie Liang


    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    Wednesday, March 22, 2017 9:41 AM
    Moderator
  • Hi Winnie

    Many thanks for your response.  The details are :

    Microsoft Outlook 2013 (15.0.4893.1000) MSO (15.0.4893.1000) 32 bit

    Product ID: 00218-02490-20695-AA703

    The macro code we are using is as follows:

    Sub MoJCopyTo2HrFolder()
    On Error Resume Next
    'MsgBox ("This is the move to 2 Hour Folder function")
    Dim ns As Outlook.NameSpace
    Dim moveToFolder As Outlook.MAPIFolder
    Dim objItem As Outlook.mailItem
    
    MsgBox ("I am in the MoJ 2Hour Macro")
    Set ns = Application.GetNamespace("MAPI")
    
    'Define path to the target folder
    Set moveToFolder = ns.Folders("_SSG Support_SSCL.MOJ.PMO").Folders("Two Hour Mails MOJ")
    
    If Application.ActiveExplorer.Selection.Count = 0 Then
       MsgBox ("No item selected")
       Exit Sub
    End If
    
    If moveToFolder Is Nothing Then
       MsgBox "Target folder not found!", vbOKOnly + vbExclamation, "Move Macro Error"
    End If
    For Each objItem In Application.ActiveExplorer.Selection
       If moveToFolder.DefaultItemType = olMailItem Then
          If objItem.Class = olMail Then
             Set objItem = objItem.Copy
             objItem.Move moveToFolder
          End If
      End If
    Next
    
    Set objItem = Nothing
    Set moveToFolder = Nothing
    Set ns = Nothing
    
    End Sub

    Thanks

    Tony



    TKHussar

    • Marked as answer by TKHussar Tuesday, June 19, 2018 10:46 AM
    Wednesday, April 12, 2017 2:30 PM