?
Solved

Printing Excel sheet from command line

Posted on 2004-08-11
14
Medium Priority
?
6,338 Views
Last Modified: 2013-12-28
I want to print MS-Excel sheet from command line. I have this script:

PRINT.EXE /D:"\\WRHMAIN\P_IS_WOFFICE" C:\projects\floor.xls

This command line is printing garbage. Any ideas how to make it work.
0
Comment
Question by:wimzieguy
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 5
14 Comments
 
LVL 2

Expert Comment

by:KJHDI12
ID: 11776175

PRINT.EXE only prints textfile. It treats the excel document as a text document, and the excel document contains alot of binary codes that reult it printing "garbage". Im looking into a solution for the printing.
0
 
LVL 2

Expert Comment

by:KJHDI12
ID: 11776500

This VB code will print a XSL document specified as a parameter. ie..
"myapp.exe" c:\test.xls"
will print the excel docuement test.xsl

If you want I can compile you a exe you can use.

Code:

Option Explicit

Public Sub Main()

   ' Variables
   Dim mybook As Excel.Workbook
   Dim xlApp As Excel.Application
   
   ' Error trapping
   On Error GoTo errTrap
   
   ' Quit if no file was specified
   If Command = "" Then Exit Sub
   
   ' Open excel document
   Set xlApp = New Excel.Application
   Set mybook = xlApp.Workbooks.Open(Command, , , , , "")
   
   ' Print
   mybook.PrintOut
   
   ' Close excel
   mybook.Close
   
   Exit Sub
errTrap:
   MsgBox Err.Description, vbInformation, "Excel document printing"
   
End Sub
0
 

Author Comment

by:wimzieguy
ID: 11776507
Please.... I am too new for visual basic
0
The Ideal Solution for Multi-Display Applications

Check out ATEN’s VS1912 12-Port DP Video Wall Media Player at InfoComm 2017. Kerri describes how easy it is to design creative video walls in asymmetric layouts and schedule detailed playlists ahead of time with its advanced scheduling feature.

 
LVL 2

Accepted Solution

by:
KJHDI12 earned 500 total points
ID: 11776599

http://www.uogateway.com/printxls.zip

It incudes the printxls.exe application and source code (just in case).
0
 

Author Comment

by:wimzieguy
ID: 11776729
I am getting this error when I run this app with my excel sheet:

The instruction at "0x00000000" referenced memory at "0x00000000". The memory could not be "read".
Click blah blah...

Any idea what is going on??
0
 
LVL 2

Expert Comment

by:KJHDI12
ID: 11776855

Strange. Anything special about that excel file?

What version of Excel do you use?
0
 

Author Comment

by:wimzieguy
ID: 11776871
Excel 97 SR-2
0
 
LVL 2

Expert Comment

by:KJHDI12
ID: 11776995

Ah. This method wont work unless you got Excel 2000 or newer. :/
0
 

Author Comment

by:wimzieguy
ID: 11777001
hmmmm... let me try then.
0
 

Author Comment

by:wimzieguy
ID: 11786718
Wow! It worked with Excel 2000 :-)
Thanks a lot!
0
 
LVL 2

Expert Comment

by:KJHDI12
ID: 11787081
np
0
 

Expert Comment

by:The_Degenerate
ID: 21944646
I am also fairly new to VB programming and needed a helping hand in figuring out how to print an excel document via VB code.  The above URL to the compiled application no longer works (it's 3 years old ..., might be why :) )  So I have re-written it in VB2005, compiled it, and am hosting it here http://www.bxstudio.com/bxdls/ExcelPrinter.exe

See attached code snippet for updated vb2005 code. Again, not a pro at VB...so the code might not be the best way to accomplish this...but it gets the job done and that is all that matters.
Also note, this code is directly derived from the above post by KJHDI12.  I don't want to take credit for his initial work.

Thanks,

Degen

Option Explicit On
 
Public Class Form1
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        ' Variables
        Dim mybook As Microsoft.Office.Interop.Excel.Workbook
        Dim xlApp As Microsoft.Office.Interop.Excel.Application
 
        ' Error trapping
        On Error GoTo errTrap
 
        ' Quit if no file was specified
        If Command() = "" Then Exit Sub
 
        ' Open excel document
        xlApp = New Microsoft.Office.Interop.Excel.Application
        mybook = xlApp.Workbooks.Open(Command, , , , , "")
 
        ' Print
        mybook.PrintOut()
 
        ' Close excel
        mybook.Close()
        Close()
        Exit Sub
errTrap:
        MsgBox(Err.Description, vbInformation, "Excel document printing")
        Close()
    End Sub
 
End Class

Open in new window

0

Featured Post

Optimum High-Definition Video Viewing and Control

The ATEN VM0404HA 4x4 4K HDMI Matrix Switch supports 4K resolutions of UHD (3840 x 2160) and DCI (4096 x 2160) with refresh rates of 30 Hz (4:4:4) and 60 Hz (4:2:0). It is ideal for applications where the routing of 4K digital signals is required.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Ever visit a website where you spotted a really cool looking Font, yet couldn't figure out which font family it belonged to, or how to get a copy of it for your own use? This article explains the process of doing exactly that, as well as showing how…
Sometimes clients can lose connectivity with the Lotus Notes Domino Server, but there's not always an obvious answer as to why it happens.   Read this article to follow one of the first experiences I had with Lotus Notes on a client's machine, my…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…
Suggested Courses

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question