Run Time -2147417856 (80010100) Error - Need help for a fix

Stildawn

Board Regular
Joined
Aug 26, 2012
Messages
197
Hi All (also asked here)

I have a complicated set of code that runs from Outlook, into excel and then in excel runs this code below:

Code:
Dim objOutl
Set objOutl = CreateObject("Outlook.Application")
Set objMailItem = objOutl.CreateItem(olMailItem)
Application.ScreenUpdating = False
ans = MsgBox("Do you need to add any attachments?", vbYesNo)
If ans = vbYes Then
    AttachFileName = Application.GetOpenFilename("Files (*.**)," & _
     "*.**", 1, "Select File", "Open", True)
    For a = LBound(AttachFileName) To UBound(AttachFileName)
        FName = Dir(AttachFileName(a))
        FileCopy AttachFileName(a), "N:\Customs\Customs_Docs\" & job & "\" & FName
    Next a
Else
End If
strEmailAddr = [EMAIL="email.address@domain.com"]email.address@domain.com[/EMAIL]
objMailItem.Recipients.Add strEmailAddr
objMailItem.Body = ""
objMailItem.Subject = sbj & "-" & pri & "-" & job
Dim MyObj As Object, MySource As Object, file1 As Variant
file1 = Dir("N:\Customs\Customs_Docs\" & job & "\")
While (file1 <> "")
    objMailItem.Attachments.Add "N:\Customs\Customs_Docs\" & job & "\" & file1
    file1 = Dir
Wend
objMailItem.Display
Set objMailItem = Nothing
Set objOutl = Nothing
Application.ScreenUpdating = True

This code works, but every so often the users get the Run Time error mentioned in the thread title... I did some googling and I found this page on a similar error regarding to Word: You may receive the "Run-time error '-2147023174' (800706ba)" error message or the "Run-time error '462'" when you run Visual Basic code that uses Automation to control Word

It looks like it would relate to my error but replace word with outlook... It seems to say that a hidden global variable reference is created and that its not released between each runs of the code?

I tried to understand all that the link above said in relation to my code, but well I just don't understand it... Could one of you guru's fix my code above??

Thanks in advance
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
Perhaps you need to set a reference to Outlook before declaring your variables.
Something like:
Code:
' Under Tools | References, select:
' Microsoft Outlook 14.0 Object Library
'
' for help with Outlook code, also see http://www.outlookcode.com/
'
Dim objOutl As Outlook.Application
Dim objMailItem As Outlook.MailItem
 
Upvote 0

Forum statistics

Threads
1,214,945
Messages
6,122,393
Members
449,081
Latest member
JAMES KECULAH

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top