【问题标题】:Print range in excel vbaexcel vba中的打印范围
【发布时间】:2017-09-19 16:12:30
【问题描述】:

我有一个数据透视表,它返回数据让我知道需要打印工作表中的哪些页面。我正在考虑使用 VBA 基于枢轴进行输出。我无法让范围工作。我错过了什么?

谢谢

Sub RectangleRoundedCorners1_Click()

    If Range("M4").Value = 1 Then
        Worksheets("Pivot").PageSetup.PrintArea = "A1:H35"
        ActiveSheet.PrintOut

        If Range("M5").Value = 2 Then Worksheets("Pivot").PageSetup.PrintArea = "A36:H71"
            ActiveSheet.PrintOut

            If Range("M6").Value = 3 Then
                Range("A72:H107").PrintOut

                If Range("M7").Value = 4 Then
                    Worksheets("Pivot").PageSetup.PrintArea = "A108:H143"
                    ActiveSheet.PrintOut

                    If Range("M8").Value = 5 Then
                        Range("A144:H179").PrintOut

                        If Range("M9").Value = 6 Then
                            Range("A180:H215").PrintOut

                            If Range("M10").Value = 7 Then
                                Range("A216:H251").PrintOut

                                If Range("M11").Value = 8 Then
                                    Range("A252:H287").PrintOut

                                    If Range("M12").Value = 9 Then
                                        Range("A288:H323").PrintOut

                                        If Range("M13").Value = 10 Then
                                            Range("A324:H359").PrintOut

                                            If Range("M14").Value = 11 Then

                                                Range("A360:H395").PrintOut
                                                If Range("M15").Value = 12 Then

                                                    Range("A396:H431").PrintOut
                                            End If
                                        End If
                                    End If
                                End If
                            End If
                        End If
                    End If
                End If
            End If
        End If
    End If
End Sub

【问题讨论】:

  • 请格式化您的代码。

标签: vba printing range


【解决方案1】:

这是代码的 sn-p。您必须更改其余部分。

If Range("M6").Value = 3 Then
   Range("A72:H107").Select
   ActiveSheet.PageSetup.PrintArea = "A72:H107"
   ActiveWindow.SelectedSheets.PrintOut From:=1, To:=1, Copies:=1, Collate:=True

【讨论】:

  • 谢谢你的星星
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-11-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多