显示打印对话框 - 从Excel

时间:2017-08-28 05:27:43

标签: excel-vba printing dialog word-vba vba

有人可以帮助我吗?我使用邮件合并和Word文档作为标签的模板。执行邮件合并后,我需要显示打印机选择的文字打印对话框,并能够在打印机属性中设置标签详细信息。我尝试将邮件合并的目的地设置为wdSendToPrinter,以各种方式调用dialog,例如wd.Dialogs(wdDialogFilePrint).Display但没有任何作用。你还有其他建议吗?

Private Sub CommandButton1_Click() 
Dim wdDoc, wd As Object
Dim template, excel As String, merge As String

template = ThisWorkbook.Path & "\template\templateA4.docx"
excel = ThisWorkbook.Path & "\" & ThisWorkbook.Name

On Error Resume Next
 Set wd = GetObject(, "Word.Application")
  If wd Is Nothing Then
    Set wd = CreateObject("Word.Application")
  End If
On Error GoTo 0

Set wdDoc = wd.documents.Open(template)

wdDoc.Application.Visible = False

 wdDoc.MailMerge.OpenDataSource _
        Name:=excel, _
        AddToRecentFiles:=False, _
        Revert:=False, _
        Connection:="Data Source=" & excel & ";Mode=Read", _
        SQLStatement:="SELECT * FROM `List1$`"


With wdDoc.MailMerge
     .MainDocumentType = wdFormLetters
     .Destination = wdSendToNewDocument
     .SuppressBlankLines = True
     With .DataSource
      .FirstRecord = 1
      .LastRecord = 5
     End With
     .Execute Pause:=False
End With

merge = wdDoc.Application.activedocument.Name
wdDoc.Application.documents(template).Close wdDoNotSaveChanges
wdDoc.Application.Visible = True
wd.Application.documents(merge).Activate

'此时需要显示单词打印对话框

wdDoc.Application.ActiveDocument.PrintOut Background:=False

wdDoc.Application.ActiveDocument.Close wdDoNotSaveChanges
wdDoc.Close SaveChanges:=False
Set wdDoc = Nothing
wd.Application.Quit wdDoNotSaveChanges
Set wd = Nothing

End Sub

1 个答案:

答案 0 :(得分:0)

尝试使用'Position'代替wd.Dialogs(88).Show