none
Access/Office 2010 Automation Problem

    Question

  • Having trouble locating an answer to the problem I am having with automating Outlook (or Excel and Word) from Access when Office 2010 is installed (I've only tried with 32bit O2010).

    For years, using Outlook 2000, 2002 & 2003 I've used the below code to create Emails in Outlook:

    Dim objOutlook As Object
    On Error Resume Next
    ' See if Outlook is Open
    Set objOutlook = GetObject(, "Outlook.Application")

    ' If Outlook is closed, 429 results, so then open Outlook
    If Err.Number = 429 Then
        Set objOutlook = CreateObject("Outlook.application")  ', "LocalHost")
    End If

    In Office 2007 and below, this works fine on Windows XP, Vista and 7 all flavors.  With Outlook 2010, both "Set objOutlook" lines fail with error 429 (the second call, to open Outlook, executes if Outlook is open or not and usually takes 10 seconds or so to move onto the next line of code).  I've tried this on numerous Windows 7 machines (home and pro, 32 & 64) all with the same results.

    I've read comments that some DLL/OCX library functionaliy has been removed from Office 2010 because of licensing issues, but have since lost the links to those blogs. Whatever the case may be, what workaround, without having to purchase third-party software, can I use to regain this automation?  Thanks for any help.

     

    John

    Thursday, January 20, 2011 1:37 PM

All replies

  • John,

    While you are running that code in Access, it is really more of an Outlook-specific issue IMO, so I would suggest you also post this same question as a new topic in the Outlook developers forum as well. http://social.msdn.microsoft.com/Forums/en-US/outlookdev/threads

     


    Mark Burns, MCAD, MCP
    Sr. Microsoft Access Analyst/Developer
    Manager LinkedIn.Com community: Professional Microsoft Access Developers Network (PMADN)
    Thursday, January 20, 2011 2:55 PM
  • Hi Mark,

    Same thing happens in Word and Excel, I just referenced Outlook because I commonly use Outlook for emailing reports from Access Programs.  If you try open a spreadsheet in Excel with similar code, I've had the same results.

    I have posted before in Outlook forums and have just heard crickets so I was hoping to find some options here.

    Thanks,

    John

    Thursday, January 20, 2011 3:18 PM
  • By the way, the commented out  ', "LocalHost")  section in the example was suggested by other postings I've found to get around problems with Symantec's Anti Virus.  Symantec would block the creation of Excel.Applicaiton or Outlook.Application and adding the LocalHost parameter got aound that.  Not the case in my situation, but I left it there for reference.  Thanks for any help.

    John

    Thursday, January 20, 2011 6:12 PM
  • Here is code I have successfully used with A2010.


    Private Sub SendEmails()
    On Error GoTo Err_Handler
    'Last mod date 15/12/2010
    'tested
        Static lngInvalidCount As Long
        Dim blnInvalidAddress As Boolean
        Dim objOutlook As Object        'Outlook.Application
        Dim objEmail As Object      'MailItem
        Dim db As DAO.Database
        Dim rs As DAO.Recordset
        Dim strMsg As String
        Dim strMsgFinished As String
        Dim strMsgError As String
        Dim strTitle As String
        Dim strStyle As String
        Dim strSQL As String
        Dim strBodyHtml As String
        Dim strStatus As String
        Dim lngMaxBatchID As Long
        Dim blnPreviewAll As Boolean
        Dim lngPreviewLimit As Long
        Dim blnSend As Boolean
        Dim lngResult As Long
        Dim blnobjOutlooklookExists As Boolean
       
        Const cPreviewLimit As Integer = 2
        Const cOutlookMailItem As Long = 0
    '    Const cBulkEmail As Long = 7

        strMsgFinished = "Finished sending emails. "
        strMsg = "One or more email addresses were invalid." & vbCrLf _
            & "the @ may be missing" & vbCrLf _
            & "there may be 2 @'s" & vbCrLf _
            & "there may be a space in the email address" & vbCrLf _
            & "or something else is wrong with the email address."
           
        strMsgError = "There is a problem sending email to Outlook." & vbCrLf _
            & "Try again or try opening Outlook before running this utility." & vbCrLf _
            & "If that also fails, contact " & pstrDeveloper
           
        lngInvalidCount = 0
       
        ' Determine whether or not to preview or SEND the emails directly.
        '
        ' Determine how many recipients there will be.  If a small number,
        ' less than the assigned limit, then go ahead and display them ALL
       
        ' we assume the user does NOT want to preview them all,
        'but we will ask their permission.
        'blnPreviewAll = True
       
        strMsg = "The first 2 email(s) will be opened for preview" & vbCrLf & vbCrLf _
                 & "On each email open for preview, you must click 'Send' button to email it."
                
        lngResult = MsgBox(strMsg, vbExclamation + vbOKCancel, "Note!")
                 '& "Do you want to preview ALL before sending?" & vbCrLf & vbCrLf _

        ' user does NOT want to preview emails
    '    If lngResult = v Then
    '        blnPreviewAll = False
    '        blnSend = True
       
        ' User asked to cancel ... unsure of what to do.  Get outta here!
        If lngResult = vbCancel Then
            Exit Sub
        Else
            ' YES, the user is sure they want to send the emails.
            'blnPreviewAll = False  'True
            blnSend = True
        End If
       
    On Error Resume Next
       
        Set db = DBEngine(0)(0)
       
        Set objOutlook = GetObject(, "Outlook.application")
    '    If Err.Number > 0 Then
    '        Err.Clear
    '        Set objOutlook = GetObject(, "Outlook.application.10")
    '    End If
    '
    '    If Err.Number > 0 Then
    '        Err.Clear
    '        Set objOutlook = GetObject(, "Outlook.application.11")
    '    End If
    '
    '    If Err.Number > 0 Then
    '        Err.Clear
    '        Set objOutlook = GetObject(, "Outlook.application.12")
    '    End If
    '
    '    'added outlook 14 16/11/2010
    '    If Err.Number > 0 Then
    '        Err.Clear
    '        Set objOutlook = GetObject(, "Outlook.application.14")
    '    End If
       
        If Err.Number Then
            blnobjOutlooklookExists = False
            Err.Clear
           
            Set objOutlook = CreateObject("Outlook.application")
           
            ' If another error has occurred, then Outlook couldn't be opened.
            ' Inform user and abort.
            If Err.Number > 0 Then
                strMsg = "Could not open Outlook. " & vbCrLf & vbCrLf & _
                            "Either Outlook is not installed correctly,   " & vbCrLf & _
                            "or there is a problem with the installation. " & vbCrLf & vbCrLf & _
                            "Try opening Outlook before running this utility. " & vbCrLf & _
                            "If that also fails, contact " & pstrDeveloper
                MsgBox strMsg, vbCritical, "Outlook Failed to Open"
                Exit Sub
            End If
        End If
       
        On Error GoTo Err_Handler
        lngMaxBatchID = Nz(DMax("EmailBatchID", "tblEmailHistory"), 0)
        If lngMaxBatchID > 0 Then
            strSQL = "SELECT tblEmailHistory.EmailHistoryID, tblEmailHistory.ClientID, tblEmailHistory.EmailBatchID, " _
                & "tblEmailHistory.Status, tblEmailHistory.FromAddress, tblEmailHistory.ToAddress, " _
                & "tblEmailHistory.Subject,tblEmailHistory.BodyHtml, tblEmailHistory.FileName, tblEmailHistory.DateSent, " _
                & "tblEmailHistory.FullFilePath, Nz([FirstName],'Customer') AS ClientName " _
                & "FROM tblEmailHistory " _
                & "INNER JOIN tblClient " _
                & "ON tblEmailHistory.ClientID = tblClient.ClientID " _
                & "WHERE tblEmailHistory.EmailBatchID = " & lngMaxBatchID
            'Debug.Print strSQL
            Set rs = db.OpenRecordset(strSQL, dbOpenDynaset)
            'Debug.Print rs!fullfilepath
           
            Do Until rs.EOF
                Set objEmail = objOutlook.CreateItem(cOutlookMailItem)
                With objEmail
                    'Debug.Print rs!ToAddress, rs!Subject, rs!bodyhtml, rs!fullfilepath
                    blnInvalidAddress = False
                    strBodyHtml = Replace(rs!BodyHtml, "<Customer>", rs!ClientName)
                    .BodyFormat = polFormatHTML
                    .To = rs!ToAddress
                    .Subject = rs!Subject
                    .HTMLBody = strBodyHtml
                    If rs!fullfilepath <> "" Then
                        .Attachments.Add (rs!fullfilepath)
                    End If
                    '.Body = rs!Body
                    If lngPreviewLimit >= cPreviewLimit Then
                        If blnSend = True Then
                            'objEmail.send
                        Else
                            objEmail.display
                        End If
                    Else
                        objEmail.display
                    End If
                    lngPreviewLimit = lngPreviewLimit + 1
                End With
               
                'Debug.Print "sent", Now
                If blnInvalidAddress = True Then
                    strStatus = "Invalid address"
                Else
                    strStatus = "sent"
                End If
               
                rs.Edit
                rs!Status = strStatus
                rs!DateSent = Date
                rs.Update
                rs.MoveNext
                DoEvents
            Loop
        End If
       
    Exit_Handler:
        On Error Resume Next
        Set objEmail = Nothing
        Set objOutlook = Nothing
        Set rs = Nothing
        Set db = Nothing
       
        Call EnableAfterSending
       
        If lngInvalidCount > 0 Then
            strMsg = strMsgFinished & strMsg
            strTitle = "Invalid email address"
            strStyle = 16
        Else
            strMsg = strMsgFinished
            strStyle = 0
            strTitle = MTitle
        End If
        MsgBox strMsg, strStyle, strTitle
        'close the instance of Outlook created by code
        If Not blnobjOutlooklookExists Then
            objOutlook.Quit
        End If
        Exit Sub
       
    Err_Handler:
        Select Case Err.Number
        Case -2147467259
            blnInvalidAddress = True
            lngInvalidCount = lngInvalidCount + 1
            Resume Next
        Case -2147023170
            MsgBox strMsgError, vbCritical, "Can't send email to Outlook"
            Resume Next
        Case -2147221231
            MsgBox strMsgError, vbCritical, "Can't send email to Outlook"
            Resume Exit_Handler
        Case 462          'The remote server machine does not exist or is unavailable
            MsgBox "Remote server error", vbCritical, "Outlook error"
            Resume Next
        Case -2147417851   'Automation error. The server threw an exception.
            Resume Exit_Handler
        Case 287  'Application-defined or object-defined error
            Resume Next
        Case Else
            Debug.Print Err.Number, Err.Description, "SendEmails", Me.Name, Now
            Resume Exit_Handler
        End Select
    End Sub


    Jeanette Cunningham
    Thursday, January 20, 2011 9:10 PM
  • Hi Jeanette,

    Thanks for the posting and I will give this a try and reply back with results.

    John

    Thursday, January 20, 2011 11:54 PM
  • Getting some results!  Not sure if you are doing early or late binding, but I'm doing late binding.  Your code is the same as mine except I saw in your code the addition of the version of Outlook (.14 in this case) to the Outlook.application statement.

    Set objOutlook = GetObject(, "Outlook.application")) nor Set objOutlook = GetObject(, "Outlook.application.14")) work even if Outlook is open.  Always returns Err 429 for me when it should only return this if Outlook is closed.

    The next line of code that figures out if it has to Open Outlook first, Set objOutlook = CreateObject("Outlook.application") fails as well, whether Outlook is Open or Closed.  It should work if Outlook is closed.

    However, if I have Outlook Closed and add the .14 to the syntax, a new email message gets displayed just fine.  Below snipet works if Outlook is closed.

    ' See if OL is open - fails whether I use below syntax or add .14 to application.14
    Set objOutlook = GetObject(, "Outlook.application")
    If Err <> 0 then
        ' Next line tries to open Outlook and this works if I use the .14
        Set objOutlook = CreateObject("Outlook.application.14"))
        If Err <> 0 then
            ' passes test and doesn't go here
        End If
        ' Do whatever comes next

    Thanks for help.  Any other thoughts?

    John

     

    Friday, January 21, 2011 9:09 PM
  • This code:

    Set objOutlook = GetObject(, "Outlook.application.14")

    is only there to be used when developing using early binding with a reference to the appropriate outlook object libraries - I haven't actually used the early binding when developing, it is there as a reminder if I ever want to use it.

    I don't know what else to suggest as the above covers all the errors that I got with extensive testing.

     

     


    Jeanette Cunningham
    Friday, January 21, 2011 11:52 PM
  • Hi Jeanette,

    Yes, I figured that was the case as I know I can't hard code the version of Outlook in.  And I do not want to do early binding because of the different flavors I know are installed on user's machines.  It did get me further so that's positive and I can try some other options I guess and maybe get my issue resolved.  Thanks again.

    John

    Saturday, January 22, 2011 8:13 PM
  • When you say it only works when you use Set objOutlook = GetObject(, "Outlook.application.14"), are you following the correct procedure to use late binding – that means removing the references for the Outlook object library.

    Is this what you are doing when you are testing with GetObject(, "Outlook.application")?


    Jeanette Cunningham
    Saturday, January 22, 2011 10:05 PM
  • I've never added the reference to the object library whether in development or in production.  I didn't want to lock the program into having to work with one version of OL.  Although, I saw your commented out code where you walk up the ladder of versions until one actually works.

    I had this problem before with several machines using Office 2007 and running the Repair Office option corrected whatever files or registry keys were out of alignment.  No such luck in 2010.

    Saturday, January 22, 2011 10:51 PM
  • Well I built a Windows 7 Professional PC with 32 Bit Win7 and 32bit MS Office 2010 and I was able to create Emails fine, both with Outlook open and closed, using the GetObject and CreateObj calls.  So, on my Win7 Professional 64Bit machine with Office 2010 32bit installed, I totally unistalled Office 2010 and re-installed it.  Same issues, I can get the code to create an email if Outlook is closed, but all I get when Outlook is open is about a 10 second pause after it skips over the GetObject line (which is should use since Outlook is open) and tries to execute the CreateObject line of code. Jeanette, were you using Win7 32 or 64bit?

    Thanks,

    John

    Thursday, February 03, 2011 2:22 AM
  • I was using a client's new laptop with Win7 64 bit. Are you testing on a standalone pc or a networked pc?


    Jeanette Cunningham
    Thursday, February 03, 2011 3:52 AM
  • It was a workgroup network PC.

    Interestingly enough, a customer fired up a new Win7 32bit & Office 2010 had my program working fine with Access 2003 installed.  Email worked both with Outlook open or closed, and no specific reference to which version of Office in the Access code.  He then uninstalled Access 2003 (it was a trial copy - not sure why he installed it in the first place) and installed Access 2002 (full copy).  Now email does not work from my program at all.  I have to trace his steps to figure out what exactly transpired.  So I know the code does work on Win7 and Office 2010 - I don't know if it is an Access specific version issue or not.

     

    John

    Thursday, February 10, 2011 11:43 AM
  • Just tried running email routine via Access 2003 (full version) and 2010 Outlook worked both with it closed and open.  A little more info, but no solution as several of the apps I have at a particular account run on A2002 full and runtime.
    Thursday, February 10, 2011 11:53 AM
  • John,

    That makes sense - your client needs to:

    1) find and download the office registry cleaner utility.

    2) remove office XP

    3) run the utility (to fully remove all vestiges of Office 2003 from the machine)

    4) reinstall Office XP again

    You _can_ have Office peacefully exist with NEWER versions of Office if they were installed in chronological order (oldest first to newer). However doing it the other way around is _fraught_ with issues, and that is what your client just did. In short, not all of Office 2003 was removed by the uninstall routines. This could easily explain why Outlook XP seems to be having issues now.


    Mark Burns, MCAD, MCP
    Sr. Microsoft Access Analyst/Developer
    Manager LinkedIn.Com community: Professional Microsoft Access Developers Network (PMADN)
    Thursday, February 10, 2011 11:56 AM
  • Chronological order is not necessarily needed when installing access. I and others can tell you that we have installed out of chronological order without any ill effects. However we have always installed the earlier versions using a custom install, each version into its own specially created folder.

    Why would your client install A2002 when they have office 2010?

    An other thing to check is compatibility issues with small business server and access. Is your client using SBS on the server?

     


    Jeanette Cunningham
    Thursday, February 10, 2011 7:05 PM
  • Jeanette,
    Access itself isn't the problem here (per se). He is automating OUTLOOK _from_ Access, and in this latest issue, Office XP was installed after a demo Office 2003 installation was uninstalled. In THIS case, the chronolgy of the installs is of significance as it is the outlook side that is likely the problem.
    Mark Burns, MCAD, MCP
    Sr. Microsoft Access Analyst/Developer
    Manager LinkedIn.Com community: Professional Microsoft Access Developers Network (PMADN)
    Thursday, February 10, 2011 7:22 PM
  • Hi Mark,

    My understanding is that access 2002 was installed with Office 2010 - that the only access version is A2002 and the office version is 2010.

     


    Jeanette Cunningham
    Thursday, February 10, 2011 10:29 PM
  • Mark Burns,

    You might be right here. What I'll do in this case is uninstall Outlook and re-install. I remembered something happen to my Outlook, that's what I did as far as I can remember.

    Friday, February 11, 2011 6:43 AM
  • Mark/Jeanette, thanks for responses.  Here is scenario (I haven't heard back from customer so more steps may have been taken):

    Customer has been working with XP Pro, Office 2007sp2 and Access 2002sp3 Full version on his workstation just fine.  Other workers have XP Pro, Office 2003/2007 and Access 2002 Runtime.  All work fine as far as Outlook automation.  (Using SBS 2003 Server to store the program and data, not that it matters.)

    Customer recently fired up new Win7 Pro machine with Office 2010 (Word,Excel,Outlook only).  Not sure where he found the disk, but he installed Access 2003 Full Version and Outlook 2010 worked fine being called from his Access 2003 install.  He also decided to install the Access 2002 Runtime package, but did not use this.  When he realized that the Access 2003 interface looked different than before, he called and I informed him that the program was running on Access 2002 so he uninstalled Access 2003 and Access 2002 Runtime.  He then installed Access 2002 Full Version and found that Outlook 2010 would not open a new Email message from his Access program whether OL2010 was open or not.  I have not heard back from him in a few days so I do not know if he tried to uninstall again or ran a system restore or what.  Unfortunately, this is all I have on his situation.

    On my development machine (Win7 Pro 64bit, stand alone desktop), I had installed Office 2010 Professional (I belive that is the version that came in my MAPS subscription).  I then installed Access 2000, 2002 and 2003, all Full versions, no runtime, no other programs from any of the versions.  I had to then use Allen Browne's registry tweak to be able to run them at the same time for support of various customer programs I have in all flavors of Access (article is http://allenbrowne.com/bug-17.html). 

    With this setup, I am not able to open a new Outlook message from either A2000 or A2002 if Outlook 2010 is open, however I can if OL2010 is closed.  I did successfully open a new OL message from Access 2003 with OL2010 open or closed, like I would expect it to work.

    I have since repaired Office 2010 to no avail.  I have uninstalled and reinstalled Access 2002 to no avail.  I have tried to use the .14 when referencing the Create or Get Object syntax, but that doesn't work either (nor would I want this since I'm using late binding so users could have various version of Office Outlook on their machines.)

    That's a summary of my situation.  I'm trying to get another Win7 test machine up and going so I can try various scenarios without fear of messing up my development machine which is working just great.

    Thanks for help.

    John

    • Edited by John SB Tuesday, February 15, 2011 2:26 AM Clarrify only 1 version of Outlook (2010) installed throughout post
    Monday, February 14, 2011 3:48 PM
  • Sorry, but I don't have experience with several different versions of Outlook on the same computer. I assume this is where the problem is - not with having several different versions of access on the same computer.


    Jeanette Cunningham
    Monday, February 14, 2011 9:24 PM
  • I only have one version of Outlook (2010) installed, multiple version of Access installed.
    Monday, February 14, 2011 10:49 PM
  • John,

    When the user install Access 2003/2002, or was the user installing Office 2003/2002? Did the installation include OutLook 2003/2002?

    Tuesday, February 15, 2011 1:53 AM
  • I do not know the answer to the 2003 question.  I know with 2002 he originally installed the Runtime version and then uninstalled that and installed the full version of Access 2002, not office 2002.  I am waiting to hear back from him on what actually got installed on 2003 - just Access or the full Office product including Outlook.  Will report back when I find out.  Thanks.
    John B
    Tuesday, February 15, 2011 2:23 AM
  • When finding a running instance of Outlook the process has to check the running objects table for the GUID associated with the program.  I suspect there is some registry corruption.  Check HKEY_CLASSES_ROOT\Outlook.Application.
    Tuesday, February 15, 2011 5:44 AM
  • User installed Office 2010 Basic on his machine.  He then installed Access 2003 only from an Office 2003 CD, no Outlook 2003, etc.  He also installed Access 2002 Runtime.  He uninstalled Access 2003 and Access 2002 Runtime and then installed just Access 2002 full version.  That is where he is at right now and Outlook 2010 does not open a new message when called from Access, whether or not Outlook is already open or is closed.
    John B
    Saturday, February 19, 2011 8:01 PM
  • I'm not sure what I am looking for.  I see the registry entry and it looks fine.  There is a CLSID REG_SZ item that looks fine.  It is readable.  What should I be looking for?
    John B
    Saturday, February 19, 2011 8:03 PM
  • Not Valid for Outlook -- Please ignore.

     

    For 2010:
    "C:\Program Files (x86)\Microsoft Office\Office14\Outlook.exe" /REGSERVER
    "C:\Program Files (x86)\Microsoft Office\Office14\Access.exe" /REGSERVER

    For 2007:
    "C:\Program Files (x86)\Microsoft Office\Office12\Outlook.exe" /REGSERVER
    "C:\Program Files (x86)\Microsoft Office\Office12\Access.exe" /REGSERVER

    For 2003:
    "C:\Program Files (x86)\Microsoft Office\Office11\Outlook.exe" /REGSERVER
    "C:\Program Files (x86)\Microsoft Office\Office11\Access.exe" /REGSERVER

    For XP:
    "C:\Program Files (x86)\Microsoft Office\Office10\Outlook.exe" /REGSERVER
    "C:\Program Files (x86)\Microsoft Office\Office10\Access.exe" /REGSERVER

     

    • Edited by saberman Sunday, February 20, 2011 6:26 PM Bad advice
    Saturday, February 19, 2011 9:46 PM
  • I tried "C:\Program Files (x86)\Microsoft Office\Office14\Outlook.exe" /REGSERVER from the Run Command and when it executes, it says "The command line argument is not valid - Verify the switch you are using.  I was going to use RegSrv but I've only used that on DLL's and OCX's.
    John B
    Sunday, February 20, 2011 4:47 PM
  • You are correct -- it is not valid for Outlook.  I have editted the original message.

    Sunday, February 20, 2011 6:27 PM
  • Good thought though
    John B
    Sunday, February 20, 2011 7:17 PM
  • Yes but I did what I always complain about -- posting without testing the solution.
    Monday, February 21, 2011 12:32 AM
  • Hmm....did he installed Outlook 2010 with Office 2010 Basic?

    I would check going into the Win7 OS Control Panel. Go into the repair of Office 2010 and see if Outlook was install. If it is, there are known problems with Outlook 2010/Win7. Currently, I don't know if there's a solution out there.

    And if it is installed (Outlook 2010), I suggest you try uninstalling Outlook 2010 and install Outlook 2003.

    See if it works.

    Monday, February 21, 2011 1:03 AM
  • Outlook 2010 was installed along with the installation of Office 2010.  Typical (or its equivalent) was selected at time of installation, so Word/Excel/OL were all installed at once.  This was the 32bit version of Office that was installed.

    Downgrading OL is a possibility but not desirable as any new machines will be coming with Office 2010 so that is why I am trying to figure out a solution.  Certainly an option as this particular customer has machines running both Officd 2003 and 2007.  Thanks for idea.


    John B
    Monday, February 21, 2011 1:26 PM
  • BTW, Excel and Word 2010 work just fine with similar code called from Access 2k2 and 2k3 (only ones tested), whether Excel/Word already open or closed.  Just OL2010 at this point:

    'Works

    On Error Resume Next
    Set objExcel = GetObject(, "Excel.Application")
    If Err.Number <> 0 Then
        'Excel Not Open, so create Excel App
        Set objExcel = CreateObject("Excel.Application")
    End If


    John B
    Monday, February 21, 2011 8:11 PM
  • John,

    Here an alternative.

    http://www.paulsadowski.com/WSH/cdo.htm

    Not sure that's acceptable for you for the time being. Not sure it will work but at least something.

    Tuesday, February 22, 2011 1:49 AM
  • I will take a look at that to see how it may/may not fit in.  Thanks for link!
    John B
    Tuesday, February 22, 2011 2:14 AM
  • Hi everyone,

    Any news on that topic?

    I am in the same situation as you John and can't find a workaround... Did you find a solution to this problem?

    Thank you!

    Tuesday, November 15, 2011 3:33 PM
  • It's a office version incompatibility. I had the exact same problem with the following code

    Set objOutlook = CreateObject("Outlook.Application")

    The fix was

    On Error Resume Next
    Set objOutlook = CreateObject("Outlook.Application")
        If Err.Number = 429 Then
            Set objOutlook = CreateObject("Outlook.Application.14")
        End If

    Or you can Add other specific versions if you want.

    • Proposed as answer by Kavenvih Thursday, May 31, 2012 3:19 PM
    Thursday, May 31, 2012 3:19 PM
  • Hi Kavenvih,

    It looks like you use the "CreateObject" twice which doesn't make sense to me.  My original code is:

    On Error Resume Next
        Set objOutlook = GetObject(, "Outlook.Application")
        If Err.Number = 429 Then
            Set objOutlook = CreateObject("Outlook.Application")  ' Tried these too - CreateObject("Outlook.Application.14") and added ", "localhost") - Neither of these work when Outlook is Open.
        End If

    The second line which uses the "GetObject" tries to see if Outlook is open or not.  If Open, there is no error and thus it skips the next lines of code.  If Outlook is closed, error 429 results and thus it goes to the "CreateObject" line.

    If I have Outlook Closed, the "CreateObject" line executes and Email is created just fine.  However, if Outlook is open (which it generally is), the code fails quickly on the "GetObject" line and generates Err=429.  It passed the 429 test but then hangs for about 30 seconds on the "CreateObject" line and then moves on and an error occurs because neither the Get nor Create worked.  For yuks, I tried your exact code and it choked as well.  Thanks for suggestion.

    John


    John B

    Thursday, May 31, 2012 4:19 PM
  • In searching some more, I found references to getting the code to work with Outlook open by starting Outlook with Run As Administrator.  I'm not sure of the limitations but was able to get the code to work as long as I started Outlook this way.

    Also, an article was referenced http://support.microsoft.com/?scid=kb%3Ben-us%3B238610&x=10&y=11 that talks about the problem.  Didn't work for me.  Detailed talk in Microsoft Answers forum message http://answers.microsoft.com/en-us/office/forum/office_2010-customize/getobject-fails-with-outlook-2010/1ee65231-2118-4223-8c40-95a9680000f8?tab=AllReplies&page=1 Somewhat of a solution with RunAs but not ideal so if any other ideas, that would be great.

    John


    John B

    Thursday, May 31, 2012 5:43 PM