Excel中的邮件合并与Word不正确的打印

时间:2018-01-21 06:48:13

标签: excel-vba mailmerge vba excel

下面是Mail合并的代码我不知道为什么有17页正在打印,只有名字从A栏打印,

请有人帮助我并审核

Sub LabelMerge()
Dim oWord As Word.Application, oDoc As Word.Document
Dim sPath As String, i As Integer, oHeaders As Range, bPrint As Boolean
Set oHeaders = Range("A1").CurrentRegion.Rows(1)
sPath = ThisWorkbook.FullName
If MsgBox("Print out the Labels or Create New Document", vbOKCancel) = vbOK Then bPrint = True
Set oWord = CreateObject("Word.Application")
Set oDoc = oWord.Documents.Add
oWord.Visible = True
oDoc.MailMerge.MainDocumentType = wdMailingLabels
oWord.Dialogs(wdDialogLabelOptions).Show
oDoc.Activate
With oDoc.MailMerge.Fields
For i = 1 To oHeaders.Columns.Count
.Add oWord.Selection.Range, oHeaders.Cells(1, 3)
oWord.Selection.TypeParagraph 'Or " Type Text " "
    Next i
End With
oDoc.MailMerge.OpenDataSource sPath
oWord.WordBasic.mailmergepropagatelabel
oDoc.MailMerge.ViewMailMergeFieldCodes = False
oDoc.ActiveWindow.View.ShowFieldCodes = False
If bPrint = True Then
oDoc.MailMerge.Destination = wdSendToPrinter
oDoc.MailMerge.Execute
Else
oDoc.MailMerge.Destination = wdSendToNewDocument
oDoc.MailMerge.Execute
Set oDoc = Nothing
Set oWord = Nothing
End Sub

0 个答案:

没有答案