Solved

How to print an excel sheet?

Posted on 2002-03-27
3
167 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 50

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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Excel object stays open 19 73
Add a task in Outlook from access 11 39
Prevent checkbox click event occur while editing it in vb6 8 41
vbModal 12 51
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

808 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