第一种方法
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盘的新建文件夹
ucloud美国云服务器怎么样?ucloud是国内知名云计算品牌服务商家,目前推出全球多地机房的海外云服务器。UCloud主打的优势是海外多机房,目前正在进行的2021全球大促活动参与促销的云服务器机房就多达18个。UCloud新一代旗舰产品快杰云服务器已上线洛杉矶节点,覆盖北美和亚太地区,火热促销中, 首月低至7元,轻松体验具备优秀性能与极高性价比的快杰云服务器。点击进入:ucloud美国洛杉矶...
爱用云互联怎么样?爱用云是一家成立于2018年的老牌商家旗下的服务器销售品牌,是正规持证IDC/ISP/IRCS商家,主要销售国内、中国香港、国外服务器产品,线路有腾讯云国外线路、自营香港CN2线路等,都是中国大陆直连线路,非常适合免备案建站业务需求和各种负载较高的项目,同时国内服务器也有多个BGP以及高防节点。专注为个人开发者用户,中小型,大型企业用户提供一站式核心网络云端服务部署,促使用户云端...
iON Cloud怎么样?iON Cloud升级了新加坡CN2 VPS的带宽和流量最低配的原先带宽5M现在升级为10M,流量也从原先的150G升级为250G。注意,流量也仅计算出站方向。iON Cloud是Krypt旗下的云服务器品牌,成立于2019年,是美国老牌机房(1998~)krypt旗下的VPS云服务器品牌,主打国外VPS云服务器业务,均采用KVM架构,整体性能配置较高,云服务器产品质量靠...