VBA Macro Works in 2007 but errors in 2010

Status
Not open for further replies.

DStrange

Member
Outlook version
Outlook 2010 32 bit
Email Account
Exchange Server
I have this snippet of code that is giving me problems.

[h=2]On Error GoTo MoveHandler

Box = InputBox("1 for Processed" & vbNewLine & "2 for No Ticket Required" & vbNewLine & "3 To Not Move this Email")

If Box = "1" Then objItem(1).Move objFolder.Folders("Processed")

If Box = "2" Then objItem(1).Move objFolder.Folders("No Ticket Required - E-Mail")

If Box = "3" Then MsgBox ("Your email will not be moved")



In Outlook 2007, this never errored out, I could repeatedly use the macro. In 2010, this will let me move one time to either of the folders, but then will error out saying it cannot find the folders.



Anyone know what changed in 2010 that would cause my macro to not work anymore?



[/h]
 
what is the full macro code? the objFolder is likely the cause of the problem.

Here is the entirety of the code:

Sub Email()
On Error Resume Next
Dim msg As MailItem
Dim i As Integer
Dim objFolder As Outlook.MAPIFolder

Dim objNS As Outlook.NameSpace
Dim objItem As Object
Dim Box As Integer
Set objNS = Application.GetNamespace("MAPI")
Set objFolder = objNS.Folders("GSC - DNB_Global Service Center").Folders("Inbox")
Set objItem = ActiveExplorer.Selection
'Assume this is a mail folder

'####change this to your Desktop#######
Const Path As String = "C:\Users\dastra\Downloads\Attachments\"
'######################################

i = 1

'delete any previous incarnation from this macro
If Dir(Path & "message.htm") <> "" Then
Kill Path & "message.htm"
Kill Path & "message_files\*.*"
End If

'save email as HTML to Path above
Set msg = ActiveExplorer.Selection.Item(1)
msg.SaveAs Path & "message.htm", olHTML

'if attachments exist, save them each in the message_files folder
If msg.Attachments.Count > 0 Then
While i <= msg.Attachments.Count
msg.Attachments.Item(i).SaveAsFile Path & "message_files\" & msg.Attachments.Item(i).FileName
i = i + 1
Wend
End If

'mark email as read
msg.UnRead = False

On Error GoTo EditHandler
Dim DateTime As String
Dim MyInput As String
Dim ToAdd As String
Dim StartBody As String

'#####change this to your initials#####
Const Initials As String = "DS"
'######################################

'get ticket number from user, date/time from system and add into single string
MyInput = InputBox("Enter I or R followed by ticket number")
DateTime = Now()
If MyInput = "" Then GoTo EditHandler
ToAdd = MyInput & " " & DateTime & " " & Initials

'prepend body of message with ticket/date/time/initials
StartBody = msg.HTMLBody
msg.HTMLBody = ToAdd & "<br><br><br>" & StartBody

On Error Resume Next
Box = InputBox("1 for Processed" & vbNewLine & "2 for No Ticket Required" & vbNewLine & "3 To Not Move this Email")
If Box = "1" Then objItem(1).Move objFolder.Folders("Processed")
If Box = "2" Then objItem(1).Move objFolder.Folders("No Ticket Required - E-Mail")
If Box = "3" Then MsgBox ("Your email will not be moved")


' Clean Up

Set msg = Nothing

Set objFolder = Nothing

Set objNS = Nothing

Set objItem = Nothing


Exit Sub

SaveHandler:
MsgBox ("Save as HTML Failed.")
Exit Sub


EditHandler:
MsgBox ("Save Successful, but failed to edit with ticket #.")

MoveHandler:
MsgBox ("Save and Edit Successful, but move failed")

End Sub

It will never error on that top code of :Set objFolder = objNS.Folders("GSC - DNB_Global Service Center").Folders("Inbox")

however if I do Set objFolder = objNS.Folders("GSC - DNB_Global Service Center").Folders("Inbox").Folders("Processed") sometimes it will work for 10-20 uses of the macro, sometimes it will work for 1 use of the macro before I need to restart Outlook.
 
Status
Not open for further replies.
Similar threads
Thread starter Title Forum Replies Date
D VBA Macro to Print and Save email to network location Outlook VBA and Custom Forms 1
N VBA Macro To Save Emails Outlook VBA and Custom Forms 1
N Help creating a VBA macro with conditional formatting to change the font color of all external emails to red Outlook VBA and Custom Forms 5
L Modifying VBA script to delay running macro Outlook VBA and Custom Forms 3
L Macro/VBA to Reply All, with the original attachments Outlook VBA and Custom Forms 2
A VBA macro for 15 second loop in send and received just for 1 specific mailbox Outlook VBA and Custom Forms 1
G VBA Macro Using Outlook 4
R Help Revising VBA macro to delete email over different time span Outlook VBA and Custom Forms 0
L Moving emails with similar subject and find the timings between the emails using outlook VBA macro Outlook VBA and Custom Forms 1
N How can I increase/faster outlook VBA Macro Speed ? Using Outlook 2
D.Moore Folder view settings by VBA macro Outlook VBA and Custom Forms 57
J Help Please!!! Outlook 2016 - VBA Macro for replying with attachment in meeting invite Outlook VBA and Custom Forms 9
R VBA macro - new message Outlook VBA and Custom Forms 3
S Example VBA Macro - To Conditionally Change the From Account and Add a BCC Address on Emails Outlook VBA and Custom Forms 11
S VBA Macro - Run-time error '424': object required - Help Please Outlook VBA and Custom Forms 3
B VBA Macro for assigning multiple Categories to an email in my Inbox Outlook VBA and Custom Forms 1
M Slow VBA macro in Outlook Outlook VBA and Custom Forms 5
M VBA macro for Inbox's attachments search Outlook VBA and Custom Forms 0
Y VBA Macro to highlight some Keyword in mail body? Outlook VBA and Custom Forms 3
J Macro only runs within VBA Editor Outlook VBA and Custom Forms 2
D VBA macro printing attachments in shared mailbox Outlook VBA and Custom Forms 1
G VBA/Macro to remove page colour when replying or forwarding email Outlook VBA and Custom Forms 2
S Outlook 7 VBA macro for multiple filing Outlook VBA and Custom Forms 1
M Outlook VBA Macro that could retrieve/display the (From, Subject, Date Received) Outlook VBA and Custom Forms 2
Philip Rose Recreating a WORD Editing Macro to use in Outlook VBA Outlook VBA and Custom Forms 4
T Random problem in VBA macro Outlook VBA and Custom Forms 6
M recover deleted items vba macro Outlook VBA and Custom Forms 2
P Vba script including macro appears in rules but wont run Outlook VBA and Custom Forms 6
S VBA Macro to VBScript Outlook VBA and Custom Forms 1
L VBA Macro to flag sent emails Using Outlook 1
B Outlook vba macro Using Outlook 1
B Auto BCC VBA macro: how to add exceptions? Using Outlook 28
R VBA Macro to VBScript in a form- Help Please! Using Outlook 10
E Word macro running from OL VBA throwing error on Word SaveAs?? Outlook VBA and Custom Forms 8
J Outlook custom form - VBS call VBA macro Outlook VBA and Custom Forms 3
N VBA Procedure (or Macro) to Stop Outlook from Closing? Outlook VBA and Custom Forms 2
M Run external program from Outlook VBA macro Outlook VBA and Custom Forms 5
D New Macro / VBA Outlook VBA and Custom Forms 7
J Specify Font Name or Face using VBA Macro in Word Outlook VBA and Custom Forms 2
S Custom VBA forms in Outlook--how to call w/macro? Outlook VBA and Custom Forms 1
S macro ist just worling wenn vba editor is open! Outlook VBA and Custom Forms 1
C VBA in "New Outlook?" Using Outlook 0
efire9207 VBA Outlook Contacts Outlook VBA and Custom Forms 6
B Requesting VBA code to make Outlook prompt for confirmation when deleting a task? Outlook VBA and Custom Forms 4
M Outlook 365 VBA Auto-Forward Only the first of Duplicate Emails Outlook VBA and Custom Forms 2
N VBA Code Not Working correctly Outlook VBA and Custom Forms 1
L VBA to Triage Incoming Email Outlook VBA and Custom Forms 0
J Outlook VBA to send from Non-default Account & Data Files Outlook VBA and Custom Forms 4
H using VBA to edit subject line Outlook VBA and Custom Forms 0
G Get current open draft message body from VBA Outlook VBA and Custom Forms 1

Similar threads

Back
Top