![]() |
If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. |
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
![]()
I have some code in an access database module that displays an email to send:
Const olMailItem As Long = 0 Const olFormatPlain As Long = 1 Dim olApp As Object Dim objMail As Object Set olApp = CreateObject("Outlook.Application") Set objMail = olApp.CreateItem(olMailItem) With objMail .to = strEmail .Subject = strSubject .Body = strMessage .attachments.Add (strAttachmentLocation) .Display End With Set objMail = Nothing Set olApp = Nothing This code works fine on several pcs. However on at least one of my pcs, it does not. The following line: Set objMail = olApp.CreateItem(olMailItem) Produces a run-time error, Operation Failed. All of the pcs are running Outlook 2003. The versions are slightly different (successful pc: 11.5608.5606, unsuccessful pc: 11.5608.8107) but I don't think its the version of outlook because alot of my successfull pcs have slightly different versions. I checked the virus scan software and it is not blocking any outlook scripting. I've been banging my head against a wall for 4 days now... I can't figure out why this same code would fail on certain pcs (with no real clues as to why.) Any help would be greatly appreciated! |
#2
|
|||
|
|||
![]()
Try again in the Outlook VBA editor on that PC to verify that Oultook can be
automated. Use both CreateObject for the Application object, and the intrinsic Outlook.Application object. Also check under Help | About | Disabled Items just to make sure that the VBA Add-In isn't disabled. These are just guesses, as I was going to finger an anti-virus app as well. However, if scripting is blocked you will not be able to use CreateObject, but explicit late-bound references to the Outlook Object Model should work. If it does, something is blocking scripting. -- Eric Legault (Outlook MVP, MCDBA, MCTS: Messaging & Collaboration) Try Picture Attachments Wizard for Outlook: http://www.collaborativeinnovations.ca Blog: http://blogs.officezealot.com/legault/ "JKro" wrote: I have some code in an access database module that displays an email to send: Const olMailItem As Long = 0 Const olFormatPlain As Long = 1 Dim olApp As Object Dim objMail As Object Set olApp = CreateObject("Outlook.Application") Set objMail = olApp.CreateItem(olMailItem) With objMail .to = strEmail .Subject = strSubject .Body = strMessage .attachments.Add (strAttachmentLocation) .Display End With Set objMail = Nothing Set olApp = Nothing This code works fine on several pcs. However on at least one of my pcs, it does not. The following line: Set objMail = olApp.CreateItem(olMailItem) Produces a run-time error, Operation Failed. All of the pcs are running Outlook 2003. The versions are slightly different (successful pc: 11.5608.5606, unsuccessful pc: 11.5608.8107) but I don't think its the version of outlook because alot of my successfull pcs have slightly different versions. I checked the virus scan software and it is not blocking any outlook scripting. I've been banging my head against a wall for 4 days now... I can't figure out why this same code would fail on certain pcs (with no real clues as to why.) Any help would be greatly appreciated! |
#3
|
|||
|
|||
![]()
Hi Eric,
Thank you so much for the advice. On the PC in question, I opened up the Outlook VBA editor and it bombed on the same line: Set objMail = olApp.CreateItem(olMailItem) I also checked to see if there were any disabled items but there were not. How can I find out if something is blocking scripting? Also, I have tested this code on some other pcs (about 10 altogeter). On 5 pcs, it works successfully on. On 2 pcs, I get the error that I described above. And on 3 pcs, the email is created and displayed but when I close the email, they get the following error: Microsoft Office Outlook has encountered a problem and needs to close. We are sorry for the inconvenience. The strange thing is, if I open up outlook prior to executing this code, it works fine on all pcs. I thought this code would open up an instance of outlook so I would not have to have Outlook running at the time of execution (and this is the case on those 5 pcs where it works successfully). Am I missing something? "Eric Legault [MVP - Outlook]" wrote: Try again in the Outlook VBA editor on that PC to verify that Oultook can be automated. Use both CreateObject for the Application object, and the intrinsic Outlook.Application object. Also check under Help | About | Disabled Items just to make sure that the VBA Add-In isn't disabled. These are just guesses, as I was going to finger an anti-virus app as well. However, if scripting is blocked you will not be able to use CreateObject, but explicit late-bound references to the Outlook Object Model should work. If it does, something is blocking scripting. -- Eric Legault (Outlook MVP, MCDBA, MCTS: Messaging & Collaboration) Try Picture Attachments Wizard for Outlook: http://www.collaborativeinnovations.ca Blog: http://blogs.officezealot.com/legault/ "JKro" wrote: I have some code in an access database module that displays an email to send: Const olMailItem As Long = 0 Const olFormatPlain As Long = 1 Dim olApp As Object Dim objMail As Object Set olApp = CreateObject("Outlook.Application") Set objMail = olApp.CreateItem(olMailItem) With objMail .to = strEmail .Subject = strSubject .Body = strMessage .attachments.Add (strAttachmentLocation) .Display End With Set objMail = Nothing Set olApp = Nothing This code works fine on several pcs. However on at least one of my pcs, it does not. The following line: Set objMail = olApp.CreateItem(olMailItem) Produces a run-time error, Operation Failed. All of the pcs are running Outlook 2003. The versions are slightly different (successful pc: 11.5608.5606, unsuccessful pc: 11.5608.8107) but I don't think its the version of outlook because alot of my successfull pcs have slightly different versions. I checked the virus scan software and it is not blocking any outlook scripting. I've been banging my head against a wall for 4 days now... I can't figure out why this same code would fail on certain pcs (with no real clues as to why.) Any help would be greatly appreciated! |
#4
|
|||
|
|||
![]()
For funzies, try the code below from Access. Also note that the .Send method
will display a dialog asking the user to allow an external app to send an e-mail. Dim objOL As Outlook.Application, blnNewOutlook As Boolean Dim objExp As Outlook.Explorer Dim objNS As Outlook.NameSpace Dim objMail As Outlook.MailItem 'Retrieve an existing Outlook Application object if it is already loaded Set objOL = GetObject(, "Outlook.Application") Err.Clear If objOL Is Nothing Then 'Outlook is closed; open it Set objOL = New Outlook.Application blnNewOutlook = True End If Set objNS = objOL.GetNamespace("MAPI") If blnNewOutlook = True Then Set objExp = objOL.Explorers.Add(objNS.GetDefaultFolder(olFolde rInbox), olFolderDisplayNormal) objExp.Activate 'Show Outlook End If Set objMail = objOL.CreateItem(olMailItem) objMail.Subject = "test " & Date & " " & Time objMail.To = " objMail.Send Set objMail = Nothing If blnNewOutlook = True Then objExp.Close objOL.Quit End If Set objExp = Nothing Set objNS = Nothing Set objOL = Nothing -- Eric Legault (Outlook MVP, MCDBA, MCTS: Messaging & Collaboration) Try Picture Attachments Wizard for Outlook: http://www.collaborativeinnovations.ca Blog: http://blogs.officezealot.com/legault/ "JKro" wrote: Hi Eric, Thank you so much for the advice. On the PC in question, I opened up the Outlook VBA editor and it bombed on the same line: Set objMail = olApp.CreateItem(olMailItem) I also checked to see if there were any disabled items but there were not. How can I find out if something is blocking scripting? Also, I have tested this code on some other pcs (about 10 altogeter). On 5 pcs, it works successfully on. On 2 pcs, I get the error that I described above. And on 3 pcs, the email is created and displayed but when I close the email, they get the following error: Microsoft Office Outlook has encountered a problem and needs to close. We are sorry for the inconvenience. The strange thing is, if I open up outlook prior to executing this code, it works fine on all pcs. I thought this code would open up an instance of outlook so I would not have to have Outlook running at the time of execution (and this is the case on those 5 pcs where it works successfully). Am I missing something? "Eric Legault [MVP - Outlook]" wrote: Try again in the Outlook VBA editor on that PC to verify that Oultook can be automated. Use both CreateObject for the Application object, and the intrinsic Outlook.Application object. Also check under Help | About | Disabled Items just to make sure that the VBA Add-In isn't disabled. These are just guesses, as I was going to finger an anti-virus app as well. However, if scripting is blocked you will not be able to use CreateObject, but explicit late-bound references to the Outlook Object Model should work. If it does, something is blocking scripting. -- Eric Legault (Outlook MVP, MCDBA, MCTS: Messaging & Collaboration) Try Picture Attachments Wizard for Outlook: http://www.collaborativeinnovations.ca Blog: http://blogs.officezealot.com/legault/ "JKro" wrote: I have some code in an access database module that displays an email to send: Const olMailItem As Long = 0 Const olFormatPlain As Long = 1 Dim olApp As Object Dim objMail As Object Set olApp = CreateObject("Outlook.Application") Set objMail = olApp.CreateItem(olMailItem) With objMail .to = strEmail .Subject = strSubject .Body = strMessage .attachments.Add (strAttachmentLocation) .Display End With Set objMail = Nothing Set olApp = Nothing This code works fine on several pcs. However on at least one of my pcs, it does not. The following line: Set objMail = olApp.CreateItem(olMailItem) Produces a run-time error, Operation Failed. All of the pcs are running Outlook 2003. The versions are slightly different (successful pc: 11.5608.5606, unsuccessful pc: 11.5608.8107) but I don't think its the version of outlook because alot of my successfull pcs have slightly different versions. I checked the virus scan software and it is not blocking any outlook scripting. I've been banging my head against a wall for 4 days now... I can't figure out why this same code would fail on certain pcs (with no real clues as to why.) Any help would be greatly appreciated! |
#5
|
|||
|
|||
![]()
I tried the code that you supplied. It worked fine on one of the pcs that
was working properly before. I then tried it on the pc that was getting "Operation Failed" when executing CreateItem and that pc received the following error: ActiveX Component can't create object at the line: Set objOL = GetObject(, "Outlook.Application") I then tried it on the pc that was getting the MS Outlook error when closing the email and I received the same error as befo Microsoft Office Outlook has encountered a problem and needs to close. We are sorry for the inconvenience. Both pcs where I received errors, I tried again but first opened up Outlook and the code worked fine then. Per your note, regarding the .Send method displaying a dialog asking the user to allow an external app to send an e-mail. I downloaded "Advanced Security for Outlook" which prevents these messages from coming up (sometimes I need to programmatically email work tickets to hundreds of our vendors). "Eric Legault [MVP - Outlook]" wrote: For funzies, try the code below from Access. Also note that the .Send method will display a dialog asking the user to allow an external app to send an e-mail. Dim objOL As Outlook.Application, blnNewOutlook As Boolean Dim objExp As Outlook.Explorer Dim objNS As Outlook.NameSpace Dim objMail As Outlook.MailItem 'Retrieve an existing Outlook Application object if it is already loaded Set objOL = GetObject(, "Outlook.Application") Err.Clear If objOL Is Nothing Then 'Outlook is closed; open it Set objOL = New Outlook.Application blnNewOutlook = True End If Set objNS = objOL.GetNamespace("MAPI") If blnNewOutlook = True Then Set objExp = objOL.Explorers.Add(objNS.GetDefaultFolder(olFolde rInbox), olFolderDisplayNormal) objExp.Activate 'Show Outlook End If Set objMail = objOL.CreateItem(olMailItem) objMail.Subject = "test " & Date & " " & Time objMail.To = " objMail.Send Set objMail = Nothing If blnNewOutlook = True Then objExp.Close objOL.Quit End If Set objExp = Nothing Set objNS = Nothing Set objOL = Nothing -- Eric Legault (Outlook MVP, MCDBA, MCTS: Messaging & Collaboration) Try Picture Attachments Wizard for Outlook: http://www.collaborativeinnovations.ca Blog: http://blogs.officezealot.com/legault/ "JKro" wrote: Hi Eric, Thank you so much for the advice. On the PC in question, I opened up the Outlook VBA editor and it bombed on the same line: Set objMail = olApp.CreateItem(olMailItem) I also checked to see if there were any disabled items but there were not. How can I find out if something is blocking scripting? Also, I have tested this code on some other pcs (about 10 altogeter). On 5 pcs, it works successfully on. On 2 pcs, I get the error that I described above. And on 3 pcs, the email is created and displayed but when I close the email, they get the following error: Microsoft Office Outlook has encountered a problem and needs to close. We are sorry for the inconvenience. The strange thing is, if I open up outlook prior to executing this code, it works fine on all pcs. I thought this code would open up an instance of outlook so I would not have to have Outlook running at the time of execution (and this is the case on those 5 pcs where it works successfully). Am I missing something? "Eric Legault [MVP - Outlook]" wrote: Try again in the Outlook VBA editor on that PC to verify that Oultook can be automated. Use both CreateObject for the Application object, and the intrinsic Outlook.Application object. Also check under Help | About | Disabled Items just to make sure that the VBA Add-In isn't disabled. These are just guesses, as I was going to finger an anti-virus app as well. However, if scripting is blocked you will not be able to use CreateObject, but explicit late-bound references to the Outlook Object Model should work. If it does, something is blocking scripting. -- Eric Legault (Outlook MVP, MCDBA, MCTS: Messaging & Collaboration) Try Picture Attachments Wizard for Outlook: http://www.collaborativeinnovations.ca Blog: http://blogs.officezealot.com/legault/ "JKro" wrote: I have some code in an access database module that displays an email to send: Const olMailItem As Long = 0 Const olFormatPlain As Long = 1 Dim olApp As Object Dim objMail As Object Set olApp = CreateObject("Outlook.Application") Set objMail = olApp.CreateItem(olMailItem) With objMail .to = strEmail .Subject = strSubject .Body = strMessage .attachments.Add (strAttachmentLocation) .Display End With Set objMail = Nothing Set olApp = Nothing This code works fine on several pcs. However on at least one of my pcs, it does not. The following line: Set objMail = olApp.CreateItem(olMailItem) Produces a run-time error, Operation Failed. All of the pcs are running Outlook 2003. The versions are slightly different (successful pc: 11.5608.5606, unsuccessful pc: 11.5608.8107) but I don't think its the version of outlook because alot of my successfull pcs have slightly different versions. I checked the virus scan software and it is not blocking any outlook scripting. I've been banging my head against a wall for 4 days now... I can't figure out why this same code would fail on certain pcs (with no real clues as to why.) Any help would be greatly appreciated! |
#6
|
|||
|
|||
![]()
To clarify, an error on that line is expected if Outlook is not running, so
add "On Error Resume Next" at the top. Does the code eventually open Outlook and send an e-mail? -- Eric Legault (Outlook MVP, MCDBA, MCTS: Messaging & Collaboration) Try Picture Attachments Wizard for Outlook: http://www.collaborativeinnovations.ca Blog: http://blogs.officezealot.com/legault/ "JKro" wrote: I tried the code that you supplied. It worked fine on one of the pcs that was working properly before. I then tried it on the pc that was getting "Operation Failed" when executing CreateItem and that pc received the following error: ActiveX Component can't create object at the line: Set objOL = GetObject(, "Outlook.Application") I then tried it on the pc that was getting the MS Outlook error when closing the email and I received the same error as befo Microsoft Office Outlook has encountered a problem and needs to close. We are sorry for the inconvenience. Both pcs where I received errors, I tried again but first opened up Outlook and the code worked fine then. Per your note, regarding the .Send method displaying a dialog asking the user to allow an external app to send an e-mail. I downloaded "Advanced Security for Outlook" which prevents these messages from coming up (sometimes I need to programmatically email work tickets to hundreds of our vendors). "Eric Legault [MVP - Outlook]" wrote: For funzies, try the code below from Access. Also note that the .Send method will display a dialog asking the user to allow an external app to send an e-mail. Dim objOL As Outlook.Application, blnNewOutlook As Boolean Dim objExp As Outlook.Explorer Dim objNS As Outlook.NameSpace Dim objMail As Outlook.MailItem 'Retrieve an existing Outlook Application object if it is already loaded Set objOL = GetObject(, "Outlook.Application") Err.Clear If objOL Is Nothing Then 'Outlook is closed; open it Set objOL = New Outlook.Application blnNewOutlook = True End If Set objNS = objOL.GetNamespace("MAPI") If blnNewOutlook = True Then Set objExp = objOL.Explorers.Add(objNS.GetDefaultFolder(olFolde rInbox), olFolderDisplayNormal) objExp.Activate 'Show Outlook End If Set objMail = objOL.CreateItem(olMailItem) objMail.Subject = "test " & Date & " " & Time objMail.To = " objMail.Send Set objMail = Nothing If blnNewOutlook = True Then objExp.Close objOL.Quit End If Set objExp = Nothing Set objNS = Nothing Set objOL = Nothing -- Eric Legault (Outlook MVP, MCDBA, MCTS: Messaging & Collaboration) Try Picture Attachments Wizard for Outlook: http://www.collaborativeinnovations.ca Blog: http://blogs.officezealot.com/legault/ "JKro" wrote: Hi Eric, Thank you so much for the advice. On the PC in question, I opened up the Outlook VBA editor and it bombed on the same line: Set objMail = olApp.CreateItem(olMailItem) I also checked to see if there were any disabled items but there were not. How can I find out if something is blocking scripting? Also, I have tested this code on some other pcs (about 10 altogeter). On 5 pcs, it works successfully on. On 2 pcs, I get the error that I described above. And on 3 pcs, the email is created and displayed but when I close the email, they get the following error: Microsoft Office Outlook has encountered a problem and needs to close. We are sorry for the inconvenience. The strange thing is, if I open up outlook prior to executing this code, it works fine on all pcs. I thought this code would open up an instance of outlook so I would not have to have Outlook running at the time of execution (and this is the case on those 5 pcs where it works successfully). Am I missing something? "Eric Legault [MVP - Outlook]" wrote: Try again in the Outlook VBA editor on that PC to verify that Oultook can be automated. Use both CreateObject for the Application object, and the intrinsic Outlook.Application object. Also check under Help | About | Disabled Items just to make sure that the VBA Add-In isn't disabled. These are just guesses, as I was going to finger an anti-virus app as well. However, if scripting is blocked you will not be able to use CreateObject, but explicit late-bound references to the Outlook Object Model should work. If it does, something is blocking scripting. -- Eric Legault (Outlook MVP, MCDBA, MCTS: Messaging & Collaboration) Try Picture Attachments Wizard for Outlook: http://www.collaborativeinnovations.ca Blog: http://blogs.officezealot.com/legault/ "JKro" wrote: I have some code in an access database module that displays an email to send: Const olMailItem As Long = 0 Const olFormatPlain As Long = 1 Dim olApp As Object Dim objMail As Object Set olApp = CreateObject("Outlook.Application") Set objMail = olApp.CreateItem(olMailItem) With objMail .to = strEmail .Subject = strSubject .Body = strMessage .attachments.Add (strAttachmentLocation) .Display End With Set objMail = Nothing Set olApp = Nothing This code works fine on several pcs. However on at least one of my pcs, it does not. The following line: Set objMail = olApp.CreateItem(olMailItem) Produces a run-time error, Operation Failed. All of the pcs are running Outlook 2003. The versions are slightly different (successful pc: 11.5608.5606, unsuccessful pc: 11.5608.8107) but I don't think its the version of outlook because alot of my successfull pcs have slightly different versions. I checked the virus scan software and it is not blocking any outlook scripting. I've been banging my head against a wall for 4 days now... I can't figure out why this same code would fail on certain pcs (with no real clues as to why.) Any help would be greatly appreciated! |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Operation Failed | techjunkee | Outlook - Installation | 2 | March 21st 06 11:40 PM |
operation failed after installation | Bob I | Outlook - Installation | 0 | February 15th 06 09:21 PM |
Outlook.ApplicationClass.CreateItem: "The operation failed." | Bruce Wood | Outlook and VBA | 2 | February 1st 06 02:12 AM |
Error message0x8004010f Operation Failed | Jay Thomas | Outlook - General Queries | 4 | January 11th 06 08:11 PM |
Operation failed in Bcc field | Simone | Add-ins for Outlook | 2 | January 11th 06 09:27 AM |