Solved

How to print an excel sheet?

Posted on 2002-03-27
3
165 Views
Last Modified: 2010-05-02
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
0
Comment
Question by:kirtirani
  • 2
3 Comments
 
LVL 49

Accepted Solution

by:
Ryan Chong earned 50 total points
ID: 6901935
Example:

Private Sub Command1_Click()
    Dim iExcel As Excel.Application
    Dim iWBook As Workbook
    Dim iWSheet As Worksheet
    TempDBPath = "D:\Project\Icon\develop\DO.xls"
    Set iExcel = CreateObject("excel.application")
    iExcel.Visible = True
    Set iWBook = iExcel.Application.Workbooks.Open(TempDBPath)
    Set iWSheet = iWBook.Worksheets("123")
    a = "123"
    iWSheet.Cells(10, 10) = a
    iWSheet.PrintOut
'    iWSheet.PrintPreview False
    'Set iWSheet = Nothing
    'iWBook.Close True
    'Set iWBook = Nothing
    'iExcel.Quit
    'Set iExcel = Nothing
End Sub

Is this helps?
0
 
LVL 44

Expert Comment

by:bruintje
ID: 6901953
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
0
 
LVL 44

Expert Comment

by:bruintje
ID: 6901956
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
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

707 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now