首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Application.Printers返回错误消息"Object or not support this property or method“

Application.Printers返回错误消息"Object or not support this property or method“
EN

Stack Overflow用户
提问于 2011-05-06 19:05:14
回答 2查看 615关注 0票数 1

是否需要选择特定的引用才能使打印机属性可见?哪个?

EN

回答 2

Stack Overflow用户

发布于 2011-05-06 21:28:29

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

下面是一个例子:

代码语言:javascript
复制
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
票数 0
EN

Stack Overflow用户

发布于 2013-01-11 07:55:01

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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/5910473

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档