循环通过DV范围并发送到打印机

时间:2016-10-03 09:19:12

标签: excel vba printing

我有一些代码循环遍历数据验证列表并将页面打印为PDF文件,我无法弄清楚如何调整它以将页面发送到打印机而不是以PDF格式打印。

Sub Button11_Click()

Application.ScreenUpdating = False

Dim cell As Range
Dim rgDV As Range
Dim DV_Cell As Range
Dim ws As Worksheet
Dim strPath As String
Dim myFile As Variant
Dim strFile As String
Dim LA As Boolean
Dim A As Integer
Dim B As Integer


Set DV_Cell = Range("B1")

Set rgDV = Application.Range(Mid$(DV_Cell.Validation.Formula1, 2))
    A = Application.InputBox("Enter Page From")
    B = Application.InputBox("Enter Page To")
Set ws = ActiveSheet

    For Each cell In rgDV.Cells
        DV_Cell.Value = cell.Value

        strFile = Cells.Range("B1") & " Period " & Cells.Range("J1")
        strFile = Cells(5, 17).Value & "\" & strFile & ".PDF"
         ws.ExportAsFixedFormat _
         Type:=xlTypePDF, _
         Filename:=strFile, _
            Quality:=xlQualityStandard, _
            IncludeDocProperties:=True, _
            IgnorePrintAreas:=False, _
         OpenAfterPublish:=False, _
         From:=A, _
         To:=B
    Next
Application.ScreenUpdating = True
Application.ScreenUpdating = True
End Sub

有关如何做到这一点的任何建议将不胜感激。

1 个答案:

答案 0 :(得分:1)

Sub Button11_Click()

Application.ScreenUpdating = False

Dim cell As Range
Dim rgDV As Range
Dim DV_Cell As Range
Dim ws As Worksheet
Dim strPath As String
Dim myFile As Variant
Dim strFile As String
Dim LA As Boolean
Dim A As Integer
Dim B As Integer


Set DV_Cell = Range("B1")

Set rgDV = Application.Range(Mid$(DV_Cell.Validation.Formula1, 2))
     A = Application.InputBox("Enter Page From")
     B = Application.InputBox("Enter Page To")
Set ws = ActiveSheet

        For Each cell In rgDV.Cells
            DV_Cell.Value = cell.Value
                ActiveSheet.PrintOut From:=A, To:=B

        Next
Application.ScreenUpdating = True

End Sub