?
Solved

How to print an excel sheet?

Posted on 2002-03-27
3
Medium Priority
?
172 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
[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
  • 2
3 Comments
 
LVL 53

Accepted Solution

by:
Ryan Chong earned 200 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…
Suggested Courses

741 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