簡體   English   中英

如何通過 vb6 打印 excel 文件?

[英]how to print excel file via vb6?

我有一個由 vb6 應用程序創建的 excel 文件,保存后,我希望將其打印到默認打印機中。

Tnx,任何幫助將不勝感激。

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

但是,要回答您的問題,您可以使用:

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

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

無論如何,我堅持認為,您應該接受以前問題的答案,否則人們不會關心回答您的新問題。

最大限度

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM