ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   spawning Excel and giving it a Print Command (https://www.excelbanter.com/excel-programming/373668-spawning-excel-giving-print-command.html)

Merdaad

spawning Excel and giving it a Print Command
 
Can you spawn Excel from an outside program (or command line) and pass it a
filename as a parameter and ask that file be printed without opening Excel?

I don't want any operator intervanetion. I want to be able to call Excel
from an outside program (c#, .NET Application) and give Excel the filename
and a print command as a parameter.

Thanks

moon[_7_]

spawning Excel and giving it a Print Command
 

"Merdaad" schreef in bericht
...
Can you spawn Excel from an outside program (or command line) and pass it
a
filename as a parameter and ask that file be printed without opening
Excel?

I don't want any operator intervanetion. I want to be able to call Excel
from an outside program (c#, .NET Application) and give Excel the filename
and a print command as a parameter.

Thanks



I think it's not possible to printout a closed file because for printing
some data need to be read anyway. However, you can run Excel on the
background using a simple VBScript that you can create in Windows Notepad:

Dim lResult
Dim strFile
strFile = InputBox( "Workbook name please..." )
lResult = PrintSheet( strFile )

Private Function PrintSheet( strFileName )
Dim xlApp, xlWbk, xlSht
Set xlApp = CreateObject( "Excel.Application" )
Set xlWbk = xlApp.Workbooks.Open( strFileName )
xlApp.Visible = False
Set xlSht = xlWbk.Sheets( 1 )
xlSht.Activate
ActiveSheet.PrintOut
xlWbk.Close
xlApp.Quit
Set xlSht = Nothing
Set xlWbk = Nothing
Set xlApp = Nothing
End Function

'Save the code as PrintSheet.VBS on your Desktop, double click it and it
should work...



Merdaad

spawning Excel and giving it a Print Command
 
Thanks. Is it even possible to spawn Excel, pass a filename to it as a
parameter and have it start with the file/worksheet open. That way the
operator will only have to press a print button.

Thx

"moon" wrote:


"Merdaad" schreef in bericht
...
Can you spawn Excel from an outside program (or command line) and pass it
a
filename as a parameter and ask that file be printed without opening
Excel?

I don't want any operator intervanetion. I want to be able to call Excel
from an outside program (c#, .NET Application) and give Excel the filename
and a print command as a parameter.

Thanks



I think it's not possible to printout a closed file because for printing
some data need to be read anyway. However, you can run Excel on the
background using a simple VBScript that you can create in Windows Notepad:

Dim lResult
Dim strFile
strFile = InputBox( "Workbook name please..." )
lResult = PrintSheet( strFile )

Private Function PrintSheet( strFileName )
Dim xlApp, xlWbk, xlSht
Set xlApp = CreateObject( "Excel.Application" )
Set xlWbk = xlApp.Workbooks.Open( strFileName )
xlApp.Visible = False
Set xlSht = xlWbk.Sheets( 1 )
xlSht.Activate
ActiveSheet.PrintOut
xlWbk.Close
xlApp.Quit
Set xlSht = Nothing
Set xlWbk = Nothing
Set xlApp = Nothing
End Function

'Save the code as PrintSheet.VBS on your Desktop, double click it and it
should work...




moon[_7_]

spawning Excel and giving it a Print Command
 

Just set xlApp.Visible to True and remove the lines
- ActiveSheet.PrintOut
- xlWbk.Close
- xlApp.Quit

Then Excel should remain open.



"Merdaad" schreef in bericht
...
Thanks. Is it even possible to spawn Excel, pass a filename to it as a
parameter and have it start with the file/worksheet open. That way the
operator will only have to press a print button.

Thx

"moon" wrote:


"Merdaad" schreef in bericht
...
Can you spawn Excel from an outside program (or command line) and pass
it
a
filename as a parameter and ask that file be printed without opening
Excel?

I don't want any operator intervanetion. I want to be able to call
Excel
from an outside program (c#, .NET Application) and give Excel the
filename
and a print command as a parameter.

Thanks



I think it's not possible to printout a closed file because for printing
some data need to be read anyway. However, you can run Excel on the
background using a simple VBScript that you can create in Windows
Notepad:

Dim lResult
Dim strFile
strFile = InputBox( "Workbook name please..." )
lResult = PrintSheet( strFile )

Private Function PrintSheet( strFileName )
Dim xlApp, xlWbk, xlSht
Set xlApp = CreateObject( "Excel.Application" )
Set xlWbk = xlApp.Workbooks.Open( strFileName )
xlApp.Visible = False
Set xlSht = xlWbk.Sheets( 1 )
xlSht.Activate
ActiveSheet.PrintOut
xlWbk.Close
xlApp.Quit
Set xlSht = Nothing
Set xlWbk = Nothing
Set xlApp = Nothing
End Function

'Save the code as PrintSheet.VBS on your Desktop, double click it and it
should work...







All times are GMT +1. The time now is 07:21 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com