Error when trying to forward current email item

Status
Not open for further replies.

reubendayal

Senior Member
Outlook version
Outlook 365 64 bit
Email Account
Office 365 Exchange
Hi All,

I have created the below macro with all the wonderful posts from the Sliptick.com site, to use the current email in the active explorer and forward it with slight changes in the subject line and adding a message to the specific receivers.

But I seem to be receiving an error message each time I run this code and then after I select the debug option in the error message, and run the macro again, the macro works.

Code:
Public Sub ApprovalUpdate()


Dim objItem As Outlook.MailItem
Dim omail As Object
Dim NewEmail As MailItem
Dim Remail, AprMsg, Emsg, Remail2, Family As String
Dim NB, NB2 As Boolean

'***
'several steps to show a form for the user to insert/select specific info to include in the email message, etc.
'And IF statements that collect the right information to put in the email - All working well'
'****

Set objItem = GetCurrentItem()

Set omail = objItem.Forward

Set NewEmail = objItem.Forward

With NewEmail

    ....do whateever....
    .Body = Emsg & .Body
    .Recipients.ResolveAll
    .Display 'Send
End With

Unload ApprovalReceivers

Set objItem = Nothing
Set NewEmail = Nothing
Set omail = Nothing

MainAppl = ""

End Sub


Function GetCurrentItem() As Outlook.MailItem
    Dim objApp As Outlook.Application
          
    Set objApp = Application
    On Error Resume Next
    Select Case TypeName(objApp.ActiveWindow)
        Case "Explorer"
            Set GetCurrentItem = objApp.ActiveExplorer.Selection.Item(1)
        Case "Inspector"
            Set GetCurrentItem = objApp.ActiveInspector.CurrentItem
    End Select
      
    Set objApp = Nothing
End Function
 
What line does it stop on?

I have 3 errors, 2 might be just because I don't have your full code. With all 3 commented out, it works.

With NewEmail

'....do whateever.... <<== is not commented out in the code you posted. Delete the line or comment it out.
.Body = Emsg & .Body
.Recipients.ResolveAll
.Display 'Send
End With

'Unload ApprovalReceivers <== I don't have this userform

Set objItem = Nothing
Set NewEmail = Nothing
Set omail = Nothing

'MainAppl = "" <<== don't know what this is, possibly something in the userform.
 
What line does it stop on?

I have 3 errors, 2 might be just because I don't have your full code. With all 3 commented out, it works.

With NewEmail

'....do whateever.... <<== is not commented out in the code you posted. Delete the line or comment it out.
.Body = Emsg & .Body
.Recipients.ResolveAll
.Display 'Send
End With

'Unload ApprovalReceivers <== I don't have this userform

Set objItem = Nothing
Set NewEmail = Nothing
Set omail = Nothing

'MainAppl = "" <<== don't know what this is, possibly something in the userform.


Hi Diane,

Thank you for replying.

I am sorry I didn't explain the full code very well.

The error is Run-Time error '2287': Application-defined or object-defined error. And the error always stops at the line -
Set omail = objItem.Forward

And when I go in to the debugger, and hover the cursor on omail or NewEmail, it shows them to be = Nothing. But by then the macro has created a forward of the original email item, without making any of the changes I want it to do via the With statement. And while I am in the debugger, if I hit F5, the macro runs again, and this time it would execute just as planned and the new email (forward) is created just as planned.

So to my non programmer knowledge, it appears like in the first try NewEmail is Nothing, but when I rerun the macro in the debugger it sort of gets focus on the email again and works fine.

Thanks.

Reuben
 
Hi Diane,

Thank you for replying.

I am sorry I didn't explain the full code very well.

The error is Run-Time error '2287': Application-defined or object-defined error. And the error always stops at the line -
Set omail = objItem.Forward

And when I go in to the debugger, and hover the cursor on omail or NewEmail, it shows them to be = Nothing. But by then the macro has created a forward of the original email item, without making any of the changes I want it to do via the With statement. And while I am in the debugger, if I hit F5, the macro runs again, and this time it would execute just as planned and the new email (forward) is created just as planned.

So to my non programmer knowledge, it appears like in the first try NewEmail is Nothing, but when I rerun the macro in the debugger it sort of gets focus on the email again and works fine.

Thanks.

Reuben
Note: a quick correction - it is Run-Time error '287'.
 
i just noticed this:
Set omail = objItem.Forward

Set NewEmail = objItem.Forward


Remove the omail lines - you aren't using that object. It didn't cause any errors for me though.


When you hover over objitem, does it show the subject? If the macro stopped on set omail, newemail will be nothing.
Set objItem = GetCurrentItem()
 
i just noticed this:
Set omail = objItem.Forward

Set NewEmail = objItem.Forward


Remove the omail lines - you aren't using that object. It didn't cause any errors for me though.


When you hover over objitem, does it show the subject? If the macro stopped on set omail, newemail will be nothing.
Set objItem = GetCurrentItem()
Tried that too... but the same result - Run-Time error '287' .
 
Tried that too... but the same result - Run-Time error '287' .
I have a solution for the problems, finally!

I have two other macros in the "ThisOutlookSession", one is for the ReplyAll event and the other an oItem_Forward. And the item forward was triggering before the intended macro or something like that as at the end of that macro the clean up routine of setting the email object to nothing was the reason.

So I added a global integer in my other macro and added an If statement at the start of the Item.forward macro to exit sub on a certain value of the global integer.

And now my other macro seems to work as normal.

Thank you anyway Diane.
 
Thanks for the update!
 
Status
Not open for further replies.
Similar threads
Thread starter Title Forum Replies Date
A Run-time error '430' on certain emails when trying to set "Outlook.mailitem" as "ActiveExplorer.Selection.Item" Outlook VBA and Custom Forms 2
N Error 0x80090326 when trying to setup IMAP account on Outlook.com Using Outlook.com accounts in Outlook 1
P Word experienced and error trying to open the file Using Outlook 2
S Trying to install BCM 2010 x64, getting error BCM (Business Contact Manager) 8
A Error: 3033 when trying to OpenDatabase using DAO Outlook VBA and Custom Forms 3
U Recovered PST file "Cannot move item" error when trying to move e- Using Outlook 6
D Error trying to connect to database on the server BCM (Business Contact Manager) 1
L Error when exporting Sent Mail to Excel Outlook VBA and Custom Forms 6
G Outlook 365 My iCloud Outlook doesn’t work after reinstalling Microsoft365 on Windows 10 PC – now I get error message on contacts and calendar Using Outlook 1
V Outlook Error The Attempted operation Failed. An Object Could Not be found Outlook VBA and Custom Forms 0
S macro error 4605 Outlook VBA and Custom Forms 0
humility36 Cannot move emails to archive - 440 error Outlook VBA and Custom Forms 1
D.Moore Strange VBA error Outlook VBA and Custom Forms 4
T Event Error on non existent Event. Using Outlook 2
P now on office 365 but getting error messages about missing Outlook 2013 cache folders Using Outlook 2
W Outlook 365 I am getting the "Either there is no default mail client" error when I try to send an email on excel Office 365 Using Outlook 1
A Links in email getting error message about group policy Using Outlook 4
Aussie Outlook 365 Rule runs manually but returns the error code "an unexpected error has occurred" when incoming mail arrives Using Outlook 1
Cathy Rhone Mail merge error message Using Outlook 1
U Outlook 2019 VBA run-time error 424 Outlook VBA and Custom Forms 2
V Outlook error 500 Using Outlook 2
O Comma Separated Values.ADR and A file error has occurred in the translator Using Outlook 6
D We're sorry but outlook has run into an error Using Outlook 6
D Outlook 2016 Outlook Error Msg "The operation cannot be performed ..." How to Stop it Using Outlook 4
P Outlook 2013 All imported Mail Rules in error when imported into new profile Using Outlook 5
H Outlook 2019 Certificate error Using Outlook 2
V Date and/or time error in Outlook Form Outlook VBA and Custom Forms 0
E Complite error on SaveAsFile method Outlook VBA and Custom Forms 2
I Error saving screenshots in a custom form in outlook 2016, outlook 365 - ok in outlook 2013, outlook 2010 Outlook VBA and Custom Forms 5
D Outlook VBA error extracting property data from GetRules collection Outlook VBA and Custom Forms 10
A Unable to save recurring Meeting to Documents folder due to error Using Outlook 2
M Compile error: User-defined type not defined Outlook VBA and Custom Forms 0
M ERROR: None of your email accounts could send to this recipient Using Outlook 2
J OLADD.FAE Error When Exporting Contacts Using Outlook 6
C Send/receive error 80040119 Using Outlook 2
W error with the permission for the file Outlook VBA and Custom Forms 0
L Outlook 2019 MAC sync error after working for 4 hours Using Outlook 1
A Run time error 424. object required in outlook 2013 Outlook VBA and Custom Forms 10
M error code 0x8DE00006 Using Outlook 1
M Desktop Version Of Outlook Generating Error Using Outlook 4
M Send/Receive error 0x800CCC0F Using Outlook 0
T Outlook 2016 CSV Translator Import Error Using Outlook 6
ManaarZakaria I'm afraid of this issue, cause of strange error Exchange Server Administration 2
P Suppress dialog box on email check error? Using Outlook 5
vodkasoda Object could not be found Error in Outlook 2007 Outlook VBA and Custom Forms 5
S VBA Macro - Run-time error '424': object required - Help Please Outlook VBA and Custom Forms 3
avant-guvnor Outlook.Application now produces error Outlook VBA and Custom Forms 5
P Run Time Error 91 when linking contact to task in VBA Outlook VBA and Custom Forms 1
N Saving And Deleting Outlook Attachments with Unknown Error Message Outlook VBA and Custom Forms 1
Dennis Gaudenzi Your setup couldn't be started because of an unexpected error (mapi 0x80040604) Using Outlook 14

Similar threads

Back
Top