spawning Excel and giving it a Print Command

G

Guest

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
 
M

moon

Merdaad said:
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...
 
G

Guest

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
 
M

moon

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

Then Excel should remain open.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top