wpsvba怎么发送邮件

软件知识 2023-07-15 20:28www.caominkang.com软件知识

psvba可以支持用户进行发送邮件,vba插件是ps中强大的功能,需要提前将vba插件安装到WPS中才能使用。我们使用一些代码编程就能够实现快速发送邮件功能。

psvba怎么发送邮件

1、将WPS中创建一个邮件地址,不同的名称也可以,在程序中用对应名称即可。

2、收件人地址从B2开始,抄送人地址从D2开始,密送收件人地址从F2开始。

3、G2是主题、H2写正文。A列、G列、E列可以填上对应的收件人名字,非必填的。

4、发送电子邮件代码

Public Sub 发送电子邮件()

Dim OutlookApp As Outlook.Application

Dim neMail As Outlook.mailitem

Dim myAttachments As Outlook.Attachments

Dim n As Integer, i As Integer

Dim s As Worksheet

On Error Resume Next

Set s = Worksheets("邮件地址")

n = s.Range("B65536").End(xlUp).Ro

address = Worksheets("邮件地址").Cells(2, 2)

For i = 2 To n

If i < n Then

address = address & ";" & Worksheets("邮件地址").Cells(i + 1, 2)

End If

Next i

'CC

n = s.Range("D65536").End(xlUp).Ro

addressCC = Worksheets("邮件地址").Cells(2, 4)

For i = 2 To n

If i < n Then

addressCC = addressCC & ";" & Worksheets("邮件地址").Cells(i + 1, 4)

End If

Next i

'BCC

n = s.Range("F65536").End(xlUp).Ro

addressBCC = Worksheets("邮件地址").Cells(2, 6)

For i = 2 To n

If i < n Then

addressBCC = addressBCC & ";" & Worksheets("邮件地址").Cells(i + 1, 6)

End If

Next i

Set OutlookApp = Ne Outlook.Application

bStr = ThisWorkbook.FullName '指定要发送发工作簿名称字符串

Set neMail = OutlookApp.CreateItem(olMailItem) '创建新邮件

With neMail

.Subject = Worksheets("邮件地址").Cells(2, 7) '设置邮件主题

.Body = Worksheets("邮件地址").Cells(2, 8) '设置邮件正文

'发送附件

Set myAttachments = neMail.Attachments

myAttachments.Add bStr, olByValue, 1, "工作簿"

.To = address '收件人

.CC = addressCC '抄送

.BCC = addressBCC '密送

.Send '开始发送

End With

End Sub

5、添加加载菜单中按钮,链接到编写的程序模块;

然后我们在点击一下按钮运行程序,将邮件发送给相关收件人;

以后在需要发邮件,只需要点这个按钮即可。

 hot

Copyright © 2016-2025 www.caominkang.com 曹敏电脑维修网 版权所有 Power by