Solved

VB and Excel

Posted on 2002-06-27
6
211 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
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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

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…
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…
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 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…

803 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