how to programmatically change default account

G

Guest

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
 
G

Guest

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?
 
M

Michael Bauer [MVP - Outlook]

'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:
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top