0

I have made a quick app for a dept at work that takes users input text fields and writes them to an excel object. The challenge of the project was that it needed to create the worksheet, write to it, print it, clear out certain confidential information, then save it, (has to print before being saved). Everything works great except that when I use the print dialog to select which printer to send it to, it will only print to the user's default printer or last printer used. I don't want to change their default printers as that will confuse them and cause chaos with some other software we have that is really particular to it's printing locations. I've searched tirelessly online and only found solutions for if I am printing a word document and not a worksheet object.

I believe this is all the relevant code:

Imports Excel = Microsoft.Office.Interop.Excel
Dim objExcel As New Excel.Application 
Dim objWorkbook As Excel.Workbook     
Dim objWorksheet As Excel.Worksheet   

Dim PrintDialog1 As New PrintDialog()
Dim result As DialogResult = PrintDialog1.ShowDialog()

    If result = DialogResult.OK Then
        PrintDialog1.PrinterSettings = PrintDocument1.PrinterSettings
        objWorksheet.PrintOutEx()
        MessageBox.Show(PrintDialog1.PrinterSettings.PrinterName)
        MsgBox("Order Printing Completed")
    ElseIf result = DialogResult.Cancel Then
        objExcel.DisplayAlerts = False
        objWorkbook.Saved = True
        objWorkbook.Close(False)
        objExcel.Quit()

       System.Runtime.InteropServices.Marshal.ReleaseComObject(objWorksheet)
       System.Runtime.InteropServices.Marshal.ReleaseComObject(objWorkbook)
       System.Runtime.InteropServices.Marshal.ReleaseComObject(objExcel)
       ProgressBar1.Value = 200
       ProgressBar1.Visible = False
        Exit Sub
    End If

Also first question on Exchange, so I don't have a lot of privileges, (aka won't be able to respond to comments right away until allowed), also new to coding in general, and this websites' stricter than MLA question and answer protocol, so be kind.

5
  • What version of Excel are you using? This may be critical to addressing your question. Commented Mar 1, 2018 at 19:21
  • Of course, sorry, it's excel 2013 and windows 10. Commented Mar 1, 2018 at 19:40
  • There was a bug in Excel 2013 and earlier - regardless of what printer was selected, it would always and only print to the defined default printer. I expect that you're probably hitting that bug. Commented Mar 1, 2018 at 19:43
  • insert expletive here. are you able link any info on the bug at all? Commented Mar 1, 2018 at 20:05
  • I'm not convinced that Microsoft ever admitted that it exists. It was fixed, however, in Excel 2016. Commented Mar 1, 2018 at 20:35

1 Answer 1

0

Open the Printers & Scanners settings in Windows. At the bottom of your list of printers & scanners make sure that "Allow Windows to manage my default printer" is selected/checked/ticked.

Should fix your problem.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.