Printing Excel worksheets in Visual Basic
Can anyone tell me if and how I print an Exceal worksheet using Visual Basic
I am trying to create a program for someone who does not know anything about Excel so I need a form which can enter name, address etc and some numbers so Excel can perform the calulcations and print them
Re: Printing Excel worksheets in Visual Basic
You can use the Excel Object Model to automate Excel from VB 6.
VB Code:
Option Explicit
'Add a reference to MS Excel xx.0 Object Library
Private Sub Command1_Click()
Dim oApp As Excel.Application
Dim oWB As Excel.Workbook
Set oApp = New Excel.Application
Set oWB = oApp.Workbooks.Open("C:\Book1.xls")
oWB.Sheets("Sheet1").Cells(1, 1) = "My Name"
oWB.Save
oWB.Sheets("Sheet1").PrintOut [From], [To], [Copies], [Preview], [ActivePrinter], [PrintToFile], [Collate], [PrToFileName]
oWB.Close
Set oWB = Nothing
oApp.Quit
Set oApp = Nothing
End Sub