Check out the Shell command.
This wil allow starting every application, for excel use the excel .exe and the steering parm with the filename to print it.
Check out the Shell command.
This wil allow starting every application, for excel use the excel .exe and the steering parm with the filename to print it.
Is it possible to print an excel file from a command button?
Thanks
Lance
Place the following code in the Click() Event of a Command Button, make your own substitutions, then fire away. The code has been tested and is fully operational. Any questions, please feel free to ask
[CODE=vb]
'1st ==> Set a Reference to the Microsoft Excel X.X Object Library
Dim strPathToExcel As String, strSpreadsheetN ame As String
Dim strWorksheetNam e As String
Dim ExcelApp As New Excel.Applicati on
Dim ExcelBook As New Excel.Workbook
Dim ExcelSheet As New Excel.Worksheet
'******* Substitute your own values ********
strPathToExcel = "C:\Test\" '*
strSpreadsheetN ame = "Employees. xls" '*
strWorksheetNam e = "Employees" '*
'************** *************** ************'*
'Let's not see what is going on
ExcelApp.Visibl e = False
Set ExcelBook = ExcelApp.Workbo oks.Open(strPat hToExcel & strSpreadsheetN ame)
Set ExcelSheet = ExcelBook.Works heets(strWorksh eetName)
Place the following code in the Click() Event of a Command Button, make your own substitutions, then fire away. The code has been tested and is fully operational. Any questions, please feel free to ask
[CODE=vb]
'1st ==> Set a Reference to the Microsoft Excel X.X Object Library
Dim strPathToExcel As String, strSpreadsheetN ame As String
Dim strWorksheetNam e As String
Dim ExcelApp As New Excel.Applicati on
Dim ExcelBook As New Excel.Workbook
Dim ExcelSheet As New Excel.Worksheet
'******* Substitute your own values ********
strPathToExcel = "C:\Test\" '*
strSpreadsheetN ame = "Employees. xls" '*
strWorksheetNam e = "Employees" '*
'************** *************** ************'*
'Let's not see what is going on
ExcelApp.Visibl e = False
Set ExcelBook = ExcelApp.Workbo oks.Open(strPat hToExcel & strSpreadsheetN ame)
Set ExcelSheet = ExcelBook.Works heets(strWorksh eetName)
Now it stops saying the file cannot be found ...the path it show is the location of excel+the path to the file 'c:\excel\c:\do cuments\file.xl s cannot be found'
Now it stops saying the file cannot be found ...the path it show is the location of excel+the path to the file 'c:\excel\c:\do cuments\file.xl s cannot be found'
Post your code
the "c:" cannot exist twice in the path. You don't have to give the path to excel, just the excel spreadsheet
Comment