【问题标题】:Loop through DV range and send to printer循环通过 DV 范围并发送到打印机
【发布时间】:2016-10-03 09:19:11
【问题描述】:

我有一些代码循环通过数据验证列表并将页面打印为 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

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

【问题讨论】:

标签: excel vba printing


【解决方案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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-04-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-05-25
    • 2015-07-10
    • 2011-05-25
    • 1970-01-01
    相关资源
    最近更新 更多