Solved

VB and Excel

Posted on 2002-06-27
6
213 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
[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
6 Comments
 
LVL 44

Accepted Solution

by:
bruintje earned 100 total points
ID: 7115041
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
ID: 7115216
sorry, what is cbdPrint variable?
0
 
LVL 44

Expert Comment

by:bruintje
ID: 7115225
0
Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

 
LVL 3

Expert Comment

by:PNJ
ID: 7115832
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
ID: 7116584
ThankX a lot
0
 
LVL 44

Expert Comment

by:bruintje
ID: 7116997
glad i could help
0

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…

730 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