如何通过vb6打印excel文件?

如何通过vb6打印excel文件?,excel,printing,vb6,Excel,Printing,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

我有一个由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
您可以在这里找到很多信息:


不管怎样,我坚持认为,你应该接受你以前问题的答案,否则人们不会在意回答你的新问题


Max

如果您想获得新问题的任何答案,您应该接受以前问题的答案ones@rekcah101-如果这是解决方案,则需要将其标记为answer@rekcah101:请看这里以了解我们正在谈论的内容:@rekcah101:没问题。似乎你找到了接受的方法:)@JMax-yeh,这就是为什么我的声誉没有提升的原因,tnx-alot-bro