Link to home
Start Free TrialLog in
Avatar of kirtirani
kirtirani

asked on

How to print an excel sheet?

Hi,
I am doing some excel programming. I have one form with some text boxes. there are 2 commnads button.
Submit button :- submits the changes from the text boxes to particular cells of excel sheet.
Print button :- I want to print the excel sheet as soon as i click the print button.
Can anyone tell me how to do the print button's printing part????
Kirti
ASKER CERTIFIED SOLUTION
Avatar of Ryan Chong
Ryan Chong
Flag of Singapore image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi kirtirani,

or use the shellexecute function
http://support.microsoft.com/directory/article.asp?ID=KB;EN-US;Q238245&

this line

StartDoc = ShellExecute(hwnd, "open", "C:\My Documents\Book1.xls", "", _
      "C:\", SW_SHOWNORMAL)

change the open to print like

StartDoc = ShellExecute(hwnd, "print", "C:\My Documents\Book1.xls", "", _
      "C:\", SW_SHOWNORMAL)

HTH:O)Bruintje
reason to use shell to print is that if you close and quit excel while printing you'll get an error because you're trying to throw an object while it's still busy