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