|
求教各位老师,我现在有个需求,想在邮件合并分页保存的同时,用VBA调用QRCode控件,或者自带的Barcode Control 16.0控件,生成二维码插入到文档的页脚,二维码内容为EXCEL文件的第一列数据。 请各位老师帮忙修改
Sub myMailMerge()
Dim myMerge As MailMerge
Dim i As Integer
Dim myname As String
Dim qrCode As YHQRCode.qrCode
Dim qrCodeImage As Picture
Application.ScreenUpdating = False
Set myMerge = ActiveDocument.MailMerge
With myMerge.DataSource
If .Parent.State = wdMainAndDataSource Then
.ActiveRecord = wdFirstRecord
For i = 1 To .RecordCount
.FirstRecord = i
.LastRecord = i
.Parent.Destination = wdSendToNewDocument
myname = .DataFields(2)
.ActiveRecord = wdNextRecord
With ActiveDocument
myMerge.Execute
' 添加二维码生成代码
Set qrCode = New YHQRCode
qrCode.Text = .DataFields(1).Value ' 设置二维码内容为第一列数据
Set qrCodeImage = ActiveDocument.Shapes.AddPicture(qrCode.GeneratePicture, False, True, 0, 0)
qrCodeImage.Width = 200 ' 设置二维码图片宽度,可根据需要调整
qrCodeImage.Height = 200 ' 设置二维码图片高度,可根据需要调整
.SaveAs "C:\Users\" & myname & ""
.Close
End With
Next i
End If
End With
Application.ScreenUpdating = True
End Sub
|
|