Reference Not Set Error

uwlchemist

New Member
Joined
Aug 29, 2009
Messages
38
I am getting the dreaded "Object reference not set to an instance of an object" error on the following code. The code hangs on the ".send" line, but I haven't been able to figure out why. Furthermore, it only hange on some users computers, not all (not mine, of course, which makes troubleshooting a pain). Any insight would be greatly appreciated. Thank you!!

Code:
Sub SendLink()
'   Send a brief message notifying the project manager that a new test
'   has been completed and sends the filepath to the saved file
    Dim OutApp As Object                                '   Outlook Application
    Dim OutMail As Object                               '   New e-mail message
    Dim strFilePath As String                           '   File path of file you are notifying project manager about
    Dim ProjectNumber As Range                          '   Project number data file pertains to
    Dim strEMail As String                              '   E-mail address of project manager
    Dim Response As Integer                             '   Response to user action
    Set ProjectNumber = Range("ProjectNumber")
    strEMail = Range("EMail").Value
 
    strFilePath = ActiveWorkbook.FullNameURLEncoded
    If Range("EMail").Value = "" Then
        MsgBox "Text_
        Exit Sub
    End If
 
        Set OutApp = CreateObject("Outlook.Application")
        OutApp.Session.Logon
        Set OutMail = OutApp.CreateItem(0)
    On Error Resume Next
    With OutMail
        .To = strEMail
        .CC = ""
        .BCC = ""
        .Subject = "Text"
        .Body = "Text " _
[B][U][COLOR=red]      .Send[/COLOR][/U][/B]        
        MsgBox "Your e-mail has been sent"
    End With
 
    Set OutMail = Nothing
    Set OutApp = Nothing
 
End Sub
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
You might need to set an object reference on the computer before the code can work. The same thing happens if you try to work with a mudole that alters VBA modules without setting trust access. I've always had to do it manually.

Maybe Outlook has some similar requirement?
 
Upvote 0
Try removing the On Error Resume Next and then step throught the code.

Check what's happening with your object variables, especially OutMail

By the way, I'm assuming the underscore on the line above the highlighted line is a typo?:)
 
Upvote 0
Yeah, the red underscore is just to highlight where the code hangs. I forgot that I had the "resume next" in there...although thinking back on it I may have added it in order to make the email actually send on the machines that have this problem. I will look in to it and see what I find. Thanks.
 
Upvote 0
You might need the On Error Resume Next but it could also be hiding what's actually causing the error.
 
Upvote 0
OK...tried trouble shooting again with the "On Error Resume Next" removed. There was absolutely no change. The error appears at the ".send" command, once you say "OK" to the error, it continues on as if nothing has happened. How do I do what Glory suggested...

You might need to set an object reference on the computer before the code can work. The same thing happens if you try to work with a mudole that alters VBA modules without setting trust access.

I looked around in Outlook, and I didn't see much. All users have my signature installed so that my macros are enabled. I have this problem on 3 machines...the other 10 or so have no problems. I don't see any differences...but there is obviously something.
 
Upvote 0
Did you check the variables when the code fails?

Might give you some clues to the problem.
 
Upvote 0
This has gotten pushed to the back-burner for now...but I wanted to let you know that I didn't ignore you. I am hoping to have time to play with this again soon, but other, more catastrophic issues have come up that I need to fix. Until then....
 
Upvote 0

Forum statistics

Threads
1,215,680
Messages
6,126,188
Members
449,296
Latest member
tinneytwin

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