Is it possible to alter Excel Viewer print settings via VB.NET and, if so, what is the syntax I need to do this?

I would like my application to be able to change the printing preferences of an Excel spreadsheet opened in Excel Viewer (through the application via Process.Start()).

This application, when given a document name, searches a directory and opens that document in Excel Viewer (or Excel, if it's installed, but this is usually not the case) if it exists. I would like to make it as simple as possible for the client to use the software, including the Excel viewer. Often simply viewing these spreadsheets isn't adequate for the particular situation the program is being written for; the client would like to print the entire workbook. Unfortunately the default setting is to print active worksheets. When I say I would like to make printing as simple as possible for the client, I mean I would like them to be able to hit the 'Quick Print' button in the Home ribbon and have the entire workbook print off.

At the moment, the only way I can see to print the entire workbook is to press first the Microsoft Office Button, then Print --> Print, which opens the print dialog, then selecting 'Entire workbook' in the 'Print what' section. I would like to avoid this process entirely and have the application do this for the client so they can, like I've already mentioned, just hit the 'Quick Print' button.

I've been working on this problem since I wrote the above and have had a few breakthroughs. I'm still not exactly at the point I would like to be, but perhaps somebody can help me with the last step(s).

I ended up using a Microsoft Web Broswer control by right-clicking the toolbox and selecting 'Choose items...', then navigating to the COM Components tab and checking 'Microsoft Web Browser'. This component is called AxWebBrowser in my form.

The Excel documents being searched for now open in the web browser instead of through Excel Viewer. This is achieved by changing Process.Start(documentFilePath) to AxWebBrowser.Navigate(documentFilePath). I had to make some changes to the registry so that the document opened in the browser rather than in Excel Viewer/Excel. You can see information about that here.

I've added a button to the form that I would like to print the entire workbook present in the AxWebBrowser. At the moment I'm using the following line of code to print (without a dialog):

AxWebBrowser.ExecWB(SHDocVw.OLECMDID.OLECMDID_PRINT, SHDocVw.OLECMDEXECOPT.OLECMDEXECOPT_DONTPROMPTUSER)

I don't seem to be able to find much information about the ExecWB method online and there isn't any information about the SHDocVw namespace within VB 2010 Express (i.e., the methods don't have any associated description, which is quite useful when using new methods).

This, unfortunately, only prints the active sheet. If I do allow the print dialog to show, there is a 'Print what' section, like I mentioned before. It seems I'm back to square one in trying to alter this setting to workbook rather than active worksheet. But I feel like I'm almost there. Any advice would be hugely appreciated.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.