View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Merdaad Merdaad is offline
external usenet poster
 
Posts: 2
Default 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...