第一种方法
Sub SendWithLotus()
Dim noSession As Object,noDatabase As Object
Dim noDocument As Object,noAttachment As Object
Dim Fi leSelf As String
Dimi As Long
Co nst EM BED_ATTACHMENT= 1454
Const stSubject As String="For Lotus VBA Programming Test only"
D i m stMsg As Stri ng
Fi leSelf=ThisWorkbook Path+"\"+ThisWorkbook NamestMsg="Bst&Rgds"&vbCrLf&_
Application UserName&vbCrLf&_
"**********************
"(This's an automated e-mai l notification,please do not reply this message)"
DimvaRecipient As VariantvaRecipient=VBA Array("huangfeng8211@163 com")
'Insert Lotus Notes COM object
Set noSession=CreateObject("Notes NotesSession")
Set noDatabase=noSession GETDATABASE("","D:\notes\data\mai l3\tonyhf nsf")
If noDatabase IsOpen= False Then noDatabase OPENMAIL
Set noDocument=noDatabase CREATEDOCUMENT
Set noAttachment= noDocument CREATERICHTEXTITEM("Body")noAttachment EMBED OBJECT EMBED_ATTACHMENT,"" ,Fi leSelf
With noDocument
Fo rm="Memo"
SendTo=vaRecipient
Subject= stSubject
Body= stMsg
SAVEMESSAGEONSEND=True
PostedDate=Now()
SEND 0,vaRecipient
End With
Set noDocument=Nothing
Set noDatabase=Nothing
Set noSession=Nothing
AppActivate"Microsoft Excel"
MsgBox"This fi le be sent" ,vbInformation
EndSub
第二种方法
Sub SendWithLotus()
Dim noSession As Object,noDatabase As Object
Dim noDocument As Object,noAttachment As Object
Dim vaFi les As Variant
Dimi As Long
Co nst EM BED_ATTACHMENT= 1454
Const stSubject As String="For Lotus VBA Programming Test only"
Const stMsg As Stri ng="This fi le is for you!j ust for reference"&vbCrLf&"I am StanleyPan"
DimvaRecipient As VariantvaReci pi ent=VBA Array("stan leypan2000@hotmai l com" ,"stanley pan@Iso laAg com")vaFi les = ApplicationGetOpenFi lename(Fi leFi lter:="Excel Fi ler (*xls),*xls" , Title:="Attach fi les for outgoing E_Mai l" ,MultiSelect:=True)
If Not IsArray(vaFi les)Then Exit Sub
'Insert Lotus Notes COM object
Set noSession=CreateObject("Notes NotesSession")
Set noDatabase=noSession GETDATABASE("","D:\notes\data\mai l3\tonyhf nsf")
If noDatabase IsOpen= False Then noDatabase OPENMAIL
Set noDocument=noDatabase CREATEDOCUMENT
Set noAttachment= noDocument CREATERICHTEXTITEM("Body")
With noAttachment
For i =1 To UBound(vaFi les)
EMBED OBJECT EMBED_ATTACHMENT,"",vaFi les(i)
Next i
End With
With noDocument
Fo rm="Memo"
SendTo=vaRecipient
Subject= stSubject
Body= stMsg
SAVEMESSAGEONSEND=True
PostedDate=Now()
SEND 0,vaRecipient
End With
Set noDocument=Nothing
Set noDatabase=Nothing
Set noSession=Nothing
AppActivate"Microsoft Excel"
MsgBox"Thisfi le is send OK" ,vbInformation
EndSub
a,返回当前数据库的名称
结果
b,返回当前数据库的文件名
c,返回当前数据库的文件路径
Sub aaaaaa()
Dimno AsObject
Dim db As Object
Dim doc As Object
Dim fields As Object
Dim nofields As Object
Dimatt As Variantatt=ApplicationGetOpenFi lename(Fi leFi lter:="Excel Fi ler(*xls),*xls" ,_
Title:="Attach fi les for outgoing E_Mai l" ,MultiSelect:=True) '添加附件
Set no=CreateObj ect("notes notessession")'建立和邮件的连接
Set db=no CURRENTDATABASE'建立和邮件数据库的连接
Set doc=db CREATEDOCUMENT'创建一个新的邮件
Set fields=doc CREATERICHTEXTITEM("body") '设置新邮件的正文附件对象With fields'设置邮件的正文和附件
APPENDTEXT" this e-mai l is generated by an automated processjust for a test"ADDNEWLINE 1 '增加第一行
APPENDTEXT" please do not reply"
ADDNEWLINE 2 '增加第二行
For i = 1 To UBound(att) '添加附件
E MB ED OB J E CT 1454,"" ,att(i)
Next i
EndWith
With doc '设置新邮件的除正文和附件外的其他信息form= "Memo" '新邮件sendto=VBA Array("huangfeng8211@163 com" ,"tonyhf@cn i bm com") '发送给Subject= "this mai l isjust for testing" '主题
SAVEMESSAGEONSEND=True'是否保存发送的邮件到发件箱postdate=DateAdd("d" ,1,Date) '发送日期等于当天
SEND0'发送
EndWith
MsgBox"successfully sent out the mai l!"
Set no=Nothing'释放内存
Set db=Nothing
Set doc=Nothing
Set fields=Nothing
EndSub
在添加附件的时候如果只是想将当前的活动工作薄作为附件的话如下
注意一下,如果是1452的话,效果如下,
会出现一个提示,询问文档包含外部对象链接,是否要更新链接,如果确定的话,效果如下,会将EX CEL文件中的内容以图片形式打开,同时文件是只读格式的,
如果是1453,效果如下,
不会有提示,但是文件为只读,
如果为1454,则为正常的EX CEL文件格式,
3,提取邮件的一些信息
以上的发件人发送时间主题等信息还可以如下表示
运行结果
a,收件箱等邮箱本身就存在的
b,如果是自己创建的文件夹及子文件夹
比如在我的邮箱中有自定义的文件夹 fo lders,如果要想获取其下面的子文件夹之一的相关资料则应如下书写4,用上面的方法提取出来的发件人是有公司名称的anotes CREATENAME(adocumentGETITEMVALUE("from")(0))ABBREVIATED
如果不使用abbreviated,则结果为
如果想要输出的发件人只有名字没有公司名的话可以做如下更改
结果为
排版之后的效果如下所示
以上代码是将发件箱中的附件保存到D盘的新建文件夹
digital-vm,这家注册在罗马尼亚的公司在国内应该有不少人比较熟悉了,主要提供VPS业务,最高10Gbps带宽,还不限制流量,而且还有日本、新加坡、美国洛杉矶、英国、西班牙、荷兰、挪威、丹麦这些可选数据中心。2020年,digital-vm新增了“独立服务器”业务,暂时只限“日本”、“新加坡”机房,最高也是支持10Gbps带宽... 官方网站:https://digital-vm.co...
Budgetvm(原EZ机房),2005年成立的美国老品牌机房,主打美国4个机房(洛杉矶、芝加哥、达拉斯、迈阿密)和日本东京机房的独立服务器和VPS业务,而且不限制流量,默认提供免费的1800G DDoS防御服务,支持IPv6和IPMI,多种免费中文操作系统可供选择,独立服务器主打大硬盘,多硬盘,大内存,用户可以在后台自行安装系统等管理操作!内存可定制升级到1536G,多块硬盘随时加,14TBSA...
GreenCloudVPS最近在新加坡DC2节点上了新机器,Dual Xeon Silver 4216 CPU,DDR4内存,10Gbps网络端口,推出了几款大硬盘VPS套餐,基于KVM架构,500GB磁盘起年付30美元。除了大硬盘套餐外,还加推了几款采用NVMe硬盘的常规套餐,最低年付20美元。不过需要提醒的是,机房非直连中国,尤其是电信用户ping值感人,包括新加坡DC1也是如此。大硬盘VPS...