![]() |
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
|
|||
|
|||
![]()
Two questions on a macro:
(1) I have two separate e-mail accounts in Outlook 2003. I use an Outlook object in a Word macro to send messages which are originally generated from a Word file. Before I do this, I manually set the default to the 2nd account I have set up in Outlook (Tools/E-mail Accounts.../View or change existing e-mail accounts). Then I run the macro and have to change the default back to the 1st account which I use most often. (I change the default account since there are many messages to be sent under the 2nd account; otherwise, I'd just change the account to be used from the "Accounts" button option under the individual message.) Following is some of the code I use for the procedure described above. Is there a way to specify the account on which I want the message sent? Thanks in advance for any assistance. (2) Also, I notice that I need to have Outlook open prior to running the macro lest it generates an error. Is there something I can do so that I don't have to open Outlook beforehand? Sub umSendScores() Dim strEmail As String, intCtr As Integer, strL As String, strSubject As String, _ strBody As String, strDoc As String, strMsg As String Dim blnStarted As Boolean, objOutlookApp As Outlook.Application, objItem As Outlook.MailItem .... Set objOutlookApp = GetObject(, "Outlook.Application") If Err 0 Then Set objOutlookApp = CreateObject("Outlook.Application") blnStarted = True End If Set objItem = objOutlookApp.CreateItem(olMailItem) With objItem .To = strEmail .Subject = strSubject .Body = strBody .Display End With Set objItem = Nothing Set objOutlookApp = Nothing Else ActiveDocument.Close savechanges:=wdDoNotSaveChanges End End If -- Bryan |
Ads |
#2
|
|||
|
|||
![]() #1 In OL 07 there's a new Account property for the MailItem. Prior to that I'd recommend to use the Redemption (www.dimastr.com) for setting the account. #2 Insert On Error Resume Next before calling GetObject. -- Viele Gruesse / Best regards Michael Bauer - MVP Outlook Organize eMails: http://www.vboffice.net/product.html?id=2006063&cmd=detail&lang=en&pub=6 Am Sun, 14 Oct 2007 10:47:00 -0700 schrieb muybn: Two questions on a macro: (1) I have two separate e-mail accounts in Outlook 2003. I use an Outlook object in a Word macro to send messages which are originally generated from a Word file. Before I do this, I manually set the default to the 2nd account I have set up in Outlook (Tools/E-mail Accounts.../View or change existing e-mail accounts). Then I run the macro and have to change the default back to the 1st account which I use most often. (I change the default account since there are many messages to be sent under the 2nd account; otherwise, I'd just change the account to be used from the "Accounts" button option under the individual message.) Following is some of the code I use for the procedure described above. Is there a way to specify the account on which I want the message sent? Thanks in advance for any assistance. (2) Also, I notice that I need to have Outlook open prior to running the macro lest it generates an error. Is there something I can do so that I don't have to open Outlook beforehand? Sub umSendScores() Dim strEmail As String, intCtr As Integer, strL As String, strSubject As String, _ strBody As String, strDoc As String, strMsg As String Dim blnStarted As Boolean, objOutlookApp As Outlook.Application, objItem As Outlook.MailItem ... Set objOutlookApp = GetObject(, "Outlook.Application") If Err 0 Then Set objOutlookApp = CreateObject("Outlook.Application") blnStarted = True End If Set objItem = objOutlookApp.CreateItem(olMailItem) With objItem .To = strEmail .Subject = strSubject .Body = strBody .Display End With Set objItem = Nothing Set objOutlookApp = Nothing Else ActiveDocument.Close savechanges:=wdDoNotSaveChanges End End If |
#3
|
|||
|
|||
![]()
Thanks, Michael. I'll try your suggestions. How would the On Error...
statement open Outlook? Wouldn't this just skip over the code without executing it? -- Bryan "Michael Bauer [MVP - Outlook]" wrote: #1 In OL 07 there's a new Account property for the MailItem. Prior to that I'd recommend to use the Redemption (www.dimastr.com) for setting the account. #2 Insert On Error Resume Next before calling GetObject. -- Viele Gruesse / Best regards Michael Bauer - MVP Outlook Organize eMails: http://www.vboffice.net/product.html?id=2006063&cmd=detail&lang=en&pub=6 Am Sun, 14 Oct 2007 10:47:00 -0700 schrieb muybn: Two questions on a macro: (1) I have two separate e-mail accounts in Outlook 2003. I use an Outlook object in a Word macro to send messages which are originally generated from a Word file. Before I do this, I manually set the default to the 2nd account I have set up in Outlook (Tools/E-mail Accounts.../View or change existing e-mail accounts). Then I run the macro and have to change the default back to the 1st account which I use most often. (I change the default account since there are many messages to be sent under the 2nd account; otherwise, I'd just change the account to be used from the "Accounts" button option under the individual message.) Following is some of the code I use for the procedure described above. Is there a way to specify the account on which I want the message sent? Thanks in advance for any assistance. (2) Also, I notice that I need to have Outlook open prior to running the macro lest it generates an error. Is there something I can do so that I don't have to open Outlook beforehand? Sub umSendScores() Dim strEmail As String, intCtr As Integer, strL As String, strSubject As String, _ strBody As String, strDoc As String, strMsg As String Dim blnStarted As Boolean, objOutlookApp As Outlook.Application, objItem As Outlook.MailItem ... Set objOutlookApp = GetObject(, "Outlook.Application") If Err 0 Then Set objOutlookApp = CreateObject("Outlook.Application") blnStarted = True End If Set objItem = objOutlookApp.CreateItem(olMailItem) With objItem .To = strEmail .Subject = strSubject .Body = strBody .Display End With Set objItem = Nothing Set objOutlookApp = Nothing Else ActiveDocument.Close savechanges:=wdDoNotSaveChanges End End If |
#4
|
|||
|
|||
![]() 'On Error Resume Next' does exactly what it is saying, it continues execution even if there's an error. GetObject raises an error if the application isn't running - and without any kind of error handling the next line would not be executed. -- Viele Gruesse / Best regards Michael Bauer - MVP Outlook Organize eMails: http://www.vboffice.net/product.html?id=2006063&cmd=detail&lang=en&pub=6 Am Sun, 14 Oct 2007 22:18:02 -0700 schrieb muybn: Thanks, Michael. I'll try your suggestions. How would the On Error... statement open Outlook? Wouldn't this just skip over the code without executing it? |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Cannot Change Default Email Account | BanTam | Outlook - Installation | 3 | August 24th 07 05:32 AM |
creating new outlook account (pop or imap) programmatically | pmoore | Outlook and VBA | 1 | March 27th 07 02:18 AM |
Outlook 2002--How do I change account which email account is active? | Dana | Outlook - General Queries | 0 | December 26th 06 04:19 PM |
How to select the Internet account programmatically? | James | Outlook and VBA | 1 | October 30th 06 05:00 AM |
Programmatically change Outlook Settings | Mitchell | Outlook and VBA | 0 | June 29th 06 04:31 PM |