Solved

VB and Excel

Posted on 2002-06-27
6
208 Views
Last Modified: 2010-05-02
Hi,

I am calling an excel template from my vb app. and printing the excel sheet as follows.

xl.ActiveSheet.PrintOut

xl is excel object and everything is working fine with this statement, but I need to display the print dialog box to the user, so that the user can specifiy number of copies, paper settings, etc.

How do I display print dialog box?

Thanks for any ideas.

Chandu

0
Comment
Question by:chandukb
6 Comments
 
LVL 44

Accepted Solution

by:
bruintje earned 100 total points
Comment Utility
Hi chandukb,

-found a snippet on the net

Private Sub cmdQPrint_Click()
   Dim intBegin As Integer, intEnd As Integer
   Dim intNumCopies As Integer, intI As Integer
   Dim xlsApp As Excel.Application
   Dim w As Workbook
   Dim S As Worksheet
   
   Set xlsApp = Excel.Application
   Set w = xlsApp.Workbooks.Open("D:\Mydocument.xls")
   Set S = w.Sheets("quotation")
   
   On Error GoTo dbErrHandler
   ' Display the Print dialog box
   cbdPrint.ShowPrinter
   ' Get user-selected values from the dialog box
   intBegin = cbdPrint.FromPage
   intEnd = cbdPrint.ToPage
   intNumCopies = cbdPrint.Copies
   
   ' Print as many copies as needed
   For intI = 1 To intNumCopies
      S.PrintOut
   Next intI
   Exit Sub

dbErrHandler:
   ' User pressed Cancel button
   Exit Sub
End Sub

HAGD:O)Bruintje
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
Comment Utility
sorry, what is cbdPrint variable?
0
 
LVL 44

Expert Comment

by:bruintje
Comment Utility
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 3

Expert Comment

by:PNJ
Comment Utility
You can also do:

W.PrintOut Copies:=intNumCopies, ActivePrinter:=OutPrinter

Where "OutPrinter" is any printer in your printers folder and this doesn't set the printer to the default.
0
 
LVL 2

Author Comment

by:chandukb
Comment Utility
ThankX a lot
0
 
LVL 44

Expert Comment

by:bruintje
Comment Utility
glad i could help
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 I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
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.
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

763 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

6 Experts available now in Live!

Get 1:1 Help Now