位置:首页 > 应用软件 > wpsvba怎么发送邮件

wpsvba怎么发送邮件

时间:2024-03-12  |  作者:  |  阅读:0

wpsvba怎么发送邮件:

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

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

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

wpsvba怎么发送邮件_wishdown.com

4、发送电子邮件代码

Public Sub 发送电子邮件()

Dim OutlookApp As Outlook.Application

Dim newMail As Outlook.mailitem

Dim myAttachments As Outlook.Attachments

Dim n As Integer, i As Integer

Dim ws As Worksheet

On Error Resume Next

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

n = ws.Range("B65536").End(xlUp).Row

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 = ws.Range("D65536").End(xlUp).Row

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 = ws.Range("F65536").End(xlUp).Row

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 = New Outlook.Application

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

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

With newMail

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

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

'发送附件

Set myAttachments = newMail.Attachments

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

.To = address '收件人

.CC = addressCC '抄送

.BCC = addressBCC '密送

.Send '开始发送

End With

End Sub

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

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

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

wpsvba怎么发送邮件_wishdown.com

福利游戏

相关文章

更多

精选合集

更多

大家都在玩

热门话题

大家都在看

更多