Solved

Excel 2010 VB.Net Print Settings Fit all columns on one page

Posted on 2014-09-18
2
2,674 Views
Last Modified: 2014-09-18
I am creating an Excel worksheet for users and need to set the printing properties in code.
The problem I have is trying to find the correct property settings to "fit all columns across one page."
' Highlight the full range used on sheet and set print area and printing properties
							' objRange1 = .Range(.Cells(#1st Row, #1st Col), .Cells(#Rows, #Last Col))
							objRange1 = .Range(.Cells(1, 1), .Cells(intSpreadsheetRow, 8))
							objRange1.Select()

							With .PageSetup

								.PrintArea = objRange1.Address
								.LeftHeader = ""
								.CenterHeader = "Un-Allocated Sales Order Lines with Free Stock"
								.RightHeader = ""
								.LeftFooter = ""
								.CenterFooter = "Page &P of &N"
								.RightFooter = ""
								.PrintHeadings = False
								.PrintGridlines = False
								.PrintComments = Excel.XlPrintLocation.xlPrintNoComments
								.PrintQuality = 600
								.CenterHorizontally = False
								.CenterVertically = False
								.Orientation = Excel.XlPageOrientation.xlLandscape
								.Draft = False
								.PaperSize = Excel.XlPaperSize.xlPaperA4
								.FirstPageNumber = Excel.Constants.xlAutomatic
								.Order = Excel.XlOrder.xlDownThenOver
								.BlackAndWhite = False
								.Zoom = False
								.FitToPagesWide = 1
								'.FitToPagesTall = 0
								.PrintErrors = Excel.XlPrintErrors.xlPrintErrorsDisplayed
								.OddAndEvenPagesHeaderFooter = False
								.DifferentFirstPageHeaderFooter = False
								.ScaleWithDocHeaderFooter = True
								.AlignMarginsHeaderFooter = True
								
							End With

Open in new window

0
Comment
Question by:TeDeSm
2 Comments
 
LVL 24

Accepted Solution

by:
Phillip Burton earned 500 total points
ID: 40329982
With .PageSetup
                                                .Zoom = False
                                                .FitToPagesWide = 1
                                                .FitToPagesTall = False                                          
                                          End With
0
 

Author Closing Comment

by:TeDeSm
ID: 40330140
Thanks Phillip, nearly had it but had set .Fit ToPagesTall = 0 which did not appear to work.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.

920 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now