Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win


VB.Net  Exporting Excel Woorkbook to PDF

Posted on 2017-04-11
Medium Priority
Last Modified: 2017-04-13
I had this question after viewing How do I save an Excel spreadsheet to PDF using VB.net.

When i use the code from the solution of this above question it does what it should do with exception of the scaling of some of the pages in this doc. The first 3 or so are fine but the last 3 are maybe only 50% in size. not sure what i am missing here. Below is the simple version of code i am using to do this

Dim savePathPDF As String = "C:\Users\Documents\LSR.pdf"
        Dim saveAsFormat As Excel.XlFixedFormatType = Excel.XlFixedFormatType.xlTypePDF

        oBook.ExportAsFixedFormat(saveAsFormat, savePathPDF, Excel.XlFixedFormatQuality.xlQualityStandard, True, True, 1, , False, )


Open in new window

Question by:AlexPonnath
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
  • 4
  • 3
LVL 23

Expert Comment

ID: 42089659
The sizing of the contents in each worksheet is set in its page setup. Sounds to me like those last 3 worksheets have the scaling limit in their respective page setup set to something other than 100% (i.e. 50%)

So, if you want all worksheets scaled at 100%, you'd have to loop through each worksheet in the workbook, set the scaling to 100% and the continue with saving the workbook as a PDF.

Author Comment

ID: 42089996
Any idea how to do that ? never had to deal with scaling. Or is there a way to set it in the actual workbook ?

Author Comment

ID: 42090016
I tried the below code but with no success, i enclosed the file in question which causes that problem

With oBook.Worksheets(4).PageSetup
            .Zoom = False
            .FitToPagesWide = 1
            .FitToPagesTall = 1
 End With

Also i just tried to save doc from Excel App itself and it does scale all pages fine
Nothing ever in the clear!

This technical paper will help you implement VMware’s VM encryption as well as implement Veeam encryption which together will achieve the nothing ever in the clear goal. If a bad guy steals VMs, backups or traffic they get nothing.

LVL 23

Expert Comment

ID: 42091856

I don't see the file attachment, but looking at your code, I'd suggest the following to loop through each worksheet in the workbook and set the scaling to 100%:

Dim oWorksheet As Excel.Worksheet
For Each oWorksheet In oBook.Worksheets
    oWorksheet.PageSetup.Zoom = 100

Open in new window


Author Comment

ID: 42092467
Sorry, here is a copy of file in question.  I tried your code but that creates now an output which is to big for page which means a single page might use up 3 or 4 pages because there are some cells which no longer fit on page.
LVL 23

Accepted Solution

irudyk earned 2000 total points
ID: 42092493
I see.  Change the 2nd True statement to False

oBook.ExportAsFixedFormat(saveAsFormat, savePathPDF, Excel.XlFixedFormatQuality.xlQualityStandard, True, False, 1, , False)

Author Comment

ID: 42092738
That did the trick

Featured Post

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

Cancel future meetings from user mailboxes in Office 365 using Remove-CalendarEvents
If you need to forecast numbers -- typically for finance -- the Windows and Mac versions of Excel 2016 have a basket of tools to get the job done.
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.
This video Micro Tutorial shows how to password-protect PDF files with free software. Many software products can do this, such as Adobe Acrobat (but not Adobe Reader), Nuance PaperPort, and Nuance Power PDF, but they are not free products. This vide…

650 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