Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 216
  • Last Modified:

VB and Excel

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
chandukb
Asked:
chandukb
1 Solution
 
bruintjeCommented:
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
 
Richie_SimonettiCommented:
sorry, what is cbdPrint variable?
0
 
bruintjeCommented:
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
PNJCommented:
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
 
chandukbAuthor Commented:
ThankX a lot
0
 
bruintjeCommented:
glad i could help
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now