我已经看到很多帖子都涉及到,无论是在整个网络上还是在stackoverflow上。但是,我没有看到人们做出太多改变,并且真的在玩这个宏。使用vba通过莲花笔记发送电子邮件
好的,可以通过使用VBA的莲花笔记发送电子邮件,但是我怎样才能让这些电子邮件更酷?例如更改字体格式或颜色?更改样式,选择插入图片作为链接或嵌入它?
好了,这是我走到这一步,通过摸索和作出一些改变:
Sub SendEmail(Subject, Text)
Dim Maildb As Object
Dim mailDoc As Object
Dim body As Object
Dim session As Object
'Start a session to notes
Set session = CreateObject("Lotus.NotesSession")
'This line prompts for password of current ID noted in Notes.INI
'Call session.Initialize
Call session.Initialize("Your Password Here")
'Open the mail database in notes
Set Maildb = session.GetDatabase("Mail Server", "mail\ .nsf")
If Not Maildb.IsOpen = True Then
Call Maildb.Open
End If
'Create the mail document
Set mailDoc = Maildb.CreateDocument
Call mailDoc.ReplaceItemValue("Form", "Memo")
'Set the recipient (you can write the name of a list you saved in your Lotus Notes)
Call mailDoc.ReplaceItemValue("SendTo", "[email protected]")
'Set subject
Call mailDoc.ReplaceItemValue("Subject", Subject)
'Create and set the Body content
Set body = mailDoc.CreateRichTextItem("Body")
Call body.AppendText(Text)
'Example to create an attachment (optional)
Call body.AddNewLine(2)
'Insert an pdf attached
Call body.EmbedObject(1453, "", "C:\Desktop\Test.pdf")
Call body.AddNewLine(2) 'add line to separate text
'Message in the end of the email
Call body.AppendText("This is an automatic message.")
'Example to save the message (optional)
mailDoc.SaveMessageOnSend = True
'Send the document
'Gets the mail to appear in the Sent items folder
Call mailDoc.ReplaceItemValue("PostedDate", Now())
Call mailDoc.send(False)
'Clean Up
Set Maildb = Nothing
Set mailDoc = Nothing
Set body = Nothing
Set session = Nothing
End Sub
顺便说一句,我使用的是Windows任务计划程序调用一个VBS然后将调用宏,将调用宏以发送具有特定主题和文本的电子邮件。由于我有几个可生成电子邮件的宏,每个宏都有其主题和文本,所以我认为这会更好。
这是VBS(这可能是无用的,每个人都知道这里,但我无论如何都会分享):
'Run VBA Using VBS
Option Explicit
On Error Resume Next
ExcelMacroExample
Sub ExcelMacroExample()
Dim xlApp
Dim xlBook
Set xlApp = CreateObject("Excel.Application")
Set xlBook = xlApp.Workbooks.Open("C:\Desktop\Macros.xlsm") 'Excel filename
xlApp.Run "SendEmail" 'Excel macro name
xlApp.Quit
Set xlBook = Nothing
Set xlApp = Nothing
End Sub
你或许应该问这个作为一个问题显示*基本*代码,并提供*你*的回答(用更新/修改后的代码及说明)作为*答案*这个问题。干杯。 – 2014-10-09 18:27:18