O
obespalov
Here is some sample code (VBScript) to automate Outlook and
automatically
save the form for attachment - this could be called on the click event
of a
button:
Dim objOutlook
Dim objOutlookMsg
Dim objOutlookRecip
Dim objOutlookAttach
Dim frmSavePath
'Create the Outlook session.
Set objOutlook = CreateObject("Outlook.Application")
Set objOutlookMsg = objOutlook.CreateItem(0) 'olMailItem
With objOutlookMsg
'Add the To recipient(s) to the message.
Set objOutlookRecip = .Recipients.Add("(e-mail address removed)")
objOutlookRecip.Type = 1 'olTo
' 'Add the CC recipient(s) to the message.
' Set objOutlookRecip = .Recipients.Add("(e-mail address removed)")
' objOutlookRecip.Type = 2 'olCC
'
' 'Add the BCC recipient(s) to the message.
' Set objOutlookRecip =
..Recipients.Add("(e-mail address removed)")
' objOutlookRecip.Type = 3 'olBCC
'Set the Subject, Body, and Importance of the message.
.Subject = "This is an Automation test with Microsoft
Outlook"
.body = "This is the body of the message"
' **NOTE: if you want the body of the message to be
HTML, then use
'.HTMLbody instead of just .body
.Importance = 2 'High importance
'Resolve each Recipient's name.
For Each objOutlookRecip In .Recipients
objOutlookRecip.Resolve
Next
'Display the message before sending
.display
'If you want to add the form as an attachment, you need
to make sure it
is saved
'first and then add that file as an attachment
frmSavePath = "C:\MyForm.XML"
XDocument.SaveAs(frmSavePath)
Set objOutlookAttach = .Attachments.Add(frmSavePath)
End With
Set objOutlook = Nothing
Set objOutlookMsg = Nothing
Set objOutlookRecip = Nothing
Set objOutlookAttach = Nothing
automatically
save the form for attachment - this could be called on the click event
of a
button:
Dim objOutlook
Dim objOutlookMsg
Dim objOutlookRecip
Dim objOutlookAttach
Dim frmSavePath
'Create the Outlook session.
Set objOutlook = CreateObject("Outlook.Application")
Set objOutlookMsg = objOutlook.CreateItem(0) 'olMailItem
With objOutlookMsg
'Add the To recipient(s) to the message.
Set objOutlookRecip = .Recipients.Add("(e-mail address removed)")
objOutlookRecip.Type = 1 'olTo
' 'Add the CC recipient(s) to the message.
' Set objOutlookRecip = .Recipients.Add("(e-mail address removed)")
' objOutlookRecip.Type = 2 'olCC
'
' 'Add the BCC recipient(s) to the message.
' Set objOutlookRecip =
..Recipients.Add("(e-mail address removed)")
' objOutlookRecip.Type = 3 'olBCC
'Set the Subject, Body, and Importance of the message.
.Subject = "This is an Automation test with Microsoft
Outlook"
.body = "This is the body of the message"
' **NOTE: if you want the body of the message to be
HTML, then use
'.HTMLbody instead of just .body
.Importance = 2 'High importance
'Resolve each Recipient's name.
For Each objOutlookRecip In .Recipients
objOutlookRecip.Resolve
Next
'Display the message before sending
.display
'If you want to add the form as an attachment, you need
to make sure it
is saved
'first and then add that file as an attachment
frmSavePath = "C:\MyForm.XML"
XDocument.SaveAs(frmSavePath)
Set objOutlookAttach = .Attachments.Add(frmSavePath)
End With
Set objOutlook = Nothing
Set objOutlookMsg = Nothing
Set objOutlookRecip = Nothing
Set objOutlookAttach = Nothing