Application.Printers 返回错误消息“对象不支持此属性或方法”

发布于 2024-11-06 03:05:52 字数 33 浏览 3 评论 0原文

我是否需要选择特定的参考以使打印机属性可见?哪一个?

Do I need to select a specific Reference to make printers property visible? Which one?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

蘸点软妹酱 2024-11-13 03:05:52

Excel VBA Worksheet 对象具有 PrintPreview 方法。如果不需要默认打印机,您可以从预览屏幕中选择打印机。此外,工作表上的 PageSetup 对象具有许多属性来准备工作表进行打印。

这是一个例子:

Public Sub PrintActiveSheet_S()
  Dim worksheetPrintable As Worksheet
  Dim iLastDataRow As Integer
  Dim iRowCount As Integer
  Dim iPrintAreaEndRow As Integer
  Dim origScreenUpdating As Boolean
  Dim origCalcMode As Integer

  On Error GoTo eh

  Set worksheetPrintable = ActiveSheet

  worksheetPrintable.PageSetup.PrintArea = "$A$1:$AD$" & iPrintAreaEndRow

  'Speed up printing setup  'http://stackoverflow.com/questions/230382/how-to-print-faster-in-excel-vba
  origScreenUpdating = Application.ScreenUpdating
  Application.ScreenUpdating = False
  origCalcMode = Application.Calculation
  Application.Calculation = xlCalculationManual
  With ActiveSheet.PageSetup
    If Not .BlackAndWhite = False Then .BlackAndWhite = False
    If Not .BottomMargin = Application.InchesToPoints(0.25) Then .BottomMargin = Application.InchesToPoints(0.25)
    If Not .CenterFooter = "Page &P of &N" Then .CenterFooter = "Page &P of &N"
    If Not .CenterHeader = "" Then .CenterHeader = ""
    If Not .CenterHorizontally = True Then .CenterHorizontally = True
    If Not .CenterVertically = False Then .CenterVertically = False
    If Not .Draft = False Then .Draft = False
    If Not .FirstPageNumber = xlAutomatic Then .FirstPageNumber = xlAutomatic
    If Not .FitToPagesTall = 50 Then .FitToPagesTall = 50
    If Not .FitToPagesWide = 1 Then .FitToPagesWide = 1
    If Not .TopMargin = Application.InchesToPoints(0.25) Then .TopMargin = Application.InchesToPoints(0.25)
    If Not .FooterMargin = Application.InchesToPoints(0.25) Then .FooterMargin = Application.InchesToPoints(0.25)
    If Not .HeaderMargin = Application.InchesToPoints(0.25) Then .HeaderMargin = Application.InchesToPoints(0.25)
    If Not .LeftMargin = Application.InchesToPoints(0.25) Then .LeftMargin = Application.InchesToPoints(0.25)
    If Not .LeftFooter = "" Then .LeftFooter = ""
    If Not .LeftHeader = "" Then .LeftHeader = ""
    If Not .Order = xlDownThenOver Then .Order = xlDownThenOver
    If Not .Orientation = xlLandscape Then .Orientation = xlLandscape
    If Not .PaperSize = xlPaperLegal Then .PaperSize = xlPaperLegal
    If Not .PrintComments = xlPrintNoComments Then .PrintComments = xlPrintNoComments
    If Not .PrintGridlines = False Then .PrintGridlines = False
    If Not .PrintHeadings = False Then .PrintHeadings = False
    If Not .PrintTitleColumns = "" Then .PrintTitleColumns = ""
    If Not .PrintTitleRows = "$3:$5" Then .PrintTitleRows = "$3:$5"
    If Not .RightFooter = "" Then .RightFooter = ""
    If Not .RightHeader = "" Then .RightHeader = ""
    If Not .RightMargin = Application.InchesToPoints(0.25) Then .RightMargin = Application.InchesToPoints(0.25)
    If Not .RightFooter = Now Then .RightFooter = Now
    If Not .Zoom = False Then .Zoom = False
  End With

    worksheetPrintable.PrintPreview

  GoTo func_exit


eh:
  gEStruc.iErrNum = Err.Number
  gEStruc.sErrorDescription = Err.Description
  gEStruc.sErrorSource = Err.Source
  m_rc = iErrorHandler_F(gEStruc)

  If m_rc = CMD_RETRY Then
    Resume
  End If

func_exit:

  Application.ScreenUpdating = origScreenUpdating
  Application.Calculation = origCalcMode
  Exit Sub

End Sub

The Excel VBA Worksheet object has a PrintPreview method. You can select your printer from the Preview Screen if the default is not desirable. Also, the PageSetup object on the Worksheet has lots of properties to prepare the worksheet for printing.

Here's an example:

Public Sub PrintActiveSheet_S()
  Dim worksheetPrintable As Worksheet
  Dim iLastDataRow As Integer
  Dim iRowCount As Integer
  Dim iPrintAreaEndRow As Integer
  Dim origScreenUpdating As Boolean
  Dim origCalcMode As Integer

  On Error GoTo eh

  Set worksheetPrintable = ActiveSheet

  worksheetPrintable.PageSetup.PrintArea = "$A$1:$AD$" & iPrintAreaEndRow

  'Speed up printing setup  'http://stackoverflow.com/questions/230382/how-to-print-faster-in-excel-vba
  origScreenUpdating = Application.ScreenUpdating
  Application.ScreenUpdating = False
  origCalcMode = Application.Calculation
  Application.Calculation = xlCalculationManual
  With ActiveSheet.PageSetup
    If Not .BlackAndWhite = False Then .BlackAndWhite = False
    If Not .BottomMargin = Application.InchesToPoints(0.25) Then .BottomMargin = Application.InchesToPoints(0.25)
    If Not .CenterFooter = "Page &P of &N" Then .CenterFooter = "Page &P of &N"
    If Not .CenterHeader = "" Then .CenterHeader = ""
    If Not .CenterHorizontally = True Then .CenterHorizontally = True
    If Not .CenterVertically = False Then .CenterVertically = False
    If Not .Draft = False Then .Draft = False
    If Not .FirstPageNumber = xlAutomatic Then .FirstPageNumber = xlAutomatic
    If Not .FitToPagesTall = 50 Then .FitToPagesTall = 50
    If Not .FitToPagesWide = 1 Then .FitToPagesWide = 1
    If Not .TopMargin = Application.InchesToPoints(0.25) Then .TopMargin = Application.InchesToPoints(0.25)
    If Not .FooterMargin = Application.InchesToPoints(0.25) Then .FooterMargin = Application.InchesToPoints(0.25)
    If Not .HeaderMargin = Application.InchesToPoints(0.25) Then .HeaderMargin = Application.InchesToPoints(0.25)
    If Not .LeftMargin = Application.InchesToPoints(0.25) Then .LeftMargin = Application.InchesToPoints(0.25)
    If Not .LeftFooter = "" Then .LeftFooter = ""
    If Not .LeftHeader = "" Then .LeftHeader = ""
    If Not .Order = xlDownThenOver Then .Order = xlDownThenOver
    If Not .Orientation = xlLandscape Then .Orientation = xlLandscape
    If Not .PaperSize = xlPaperLegal Then .PaperSize = xlPaperLegal
    If Not .PrintComments = xlPrintNoComments Then .PrintComments = xlPrintNoComments
    If Not .PrintGridlines = False Then .PrintGridlines = False
    If Not .PrintHeadings = False Then .PrintHeadings = False
    If Not .PrintTitleColumns = "" Then .PrintTitleColumns = ""
    If Not .PrintTitleRows = "$3:$5" Then .PrintTitleRows = "$3:$5"
    If Not .RightFooter = "" Then .RightFooter = ""
    If Not .RightHeader = "" Then .RightHeader = ""
    If Not .RightMargin = Application.InchesToPoints(0.25) Then .RightMargin = Application.InchesToPoints(0.25)
    If Not .RightFooter = Now Then .RightFooter = Now
    If Not .Zoom = False Then .Zoom = False
  End With

    worksheetPrintable.PrintPreview

  GoTo func_exit


eh:
  gEStruc.iErrNum = Err.Number
  gEStruc.sErrorDescription = Err.Description
  gEStruc.sErrorSource = Err.Source
  m_rc = iErrorHandler_F(gEStruc)

  If m_rc = CMD_RETRY Then
    Resume
  End If

func_exit:

  Application.ScreenUpdating = origScreenUpdating
  Application.Calculation = origCalcMode
  Exit Sub

End Sub
梦回旧景 2024-11-13 03:05:52

Application.Printers 在 Excel 中不可用,但在 Access 中可用。

Application.Printers is not available in Excel, though it is in Access.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文