[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

How to print an excel sheet?

Posted on 2002-03-27
3
Medium Priority
?
173 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: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone 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

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
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 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…
Suggested Courses

649 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