【问题标题】:how to print excel file via vb6?如何通过vb6打印excel文件?
【发布时间】:2011-06-29 06:40:50
【问题描述】:

我有一个由 vb6 应用程序创建的 excel 文件,保存后,我希望将其打印到默认打印机中..,

Tnx,任何帮助将不胜感激。

【问题讨论】:

  • 如果您想对新问题有任何答案,您应该接受以前问题的答案

标签: excel printing vb6


【解决方案1】:
Private Sub Command1_Click()
    Dim xlApp As Excel.Application
    Dim xlWB As Excel.Workbook
    Dim xlSH As Excel.Worksheet

    'open excel application
    Set xlApp = New Excel.Application
    'Open excel workbook
    Set xlWB = xlApp.Workbooks.Open(FileName:="C:\YourFile.xls")
    'There are two ways to access specific worksheets
    'By index number (the first worksheet in this case)
    Set xlSH = xlWB.Worksheets(1)
    'or by the Sheet's Name
    Set xlSH = xlWB.Worksheets("TestSheet")

    PrintSheet xlSH, "MyFoot", "MyHead"

    'Close workbook (optional)
    xlWB.Close
    'Quit excel (automatically closes all workbooks)
    xlApp.Quit
    'Clean up memory (you must do this)
    Set xlWB = Nothing
    Set xlApp = Nothing
End Sub

Sub PrintSheet(sh As Worksheet, strFooter As String, strHeader As String)
    sh.PageSetup.CenterFooter = strFooter
    sh.PageSetup.CenterHeader = strHeader
    sh.PrintOut
End Sub

【讨论】:

    【解决方案2】:

    但是,要回答您的问题,您可以使用:

    ActiveWorkbook.PrintOut Copies:=1, Collate:=True
    

    你可以在这里找到很多信息:http://www.exceltip.com/excel_tips/Printing_in_VBA/210.html

    无论如何,我坚持认为,您应该接受以前问题的答案,否则人们不会在意回答您的新问题。

    最大

    【讨论】:

    • @rekcah101 - 如果这是解决方案,那么您需要将其标记为答案
    • @rekcah101:看这里了解我们在说什么:meta.stackexchange.com/questions/5234/…
    • @rekcah101:没问题。好像你找到了如何接受:)
    • @JMax - 是的..,这就是为什么我的声誉没有上升..,tnx alot bro
    猜你喜欢
    • 2015-02-16
    • 1970-01-01
    • 2023-04-09
    • 2018-04-04
    • 1970-01-01
    • 1970-01-01
    • 2014-08-25
    • 2021-07-15
    • 1970-01-01
    相关资源
    最近更新 更多