TO FIT ALL COLUMN
For Each ws In Worksheets ws.Columns.Autofit Next ws
ANOTHER SOLUTION - RECORDING MACRO
Sub Macro5() With ActiveSheet.PageSetup .LeftHeader = "" .CenterHeader = "" .RightHeader = "" .LeftFooter = "" .CenterFooter = "" .RightFooter = "" .LeftMargin = Application.InchesToPoints(0) .RightMargin = Application.InchesToPoints(0) .TopMargin = Application.InchesToPoints(1) .BottomMargin = Application.InchesToPoints(1) .HeaderMargin = Application.InchesToPoints(0.5) .FooterMargin = Application.InchesToPoints(0.5) .PrintHeadings = False .PrintGridlines = False .PrintComments = xlPrintNoComments .PrintQuality = 600 .CenterHorizontally = False .CenterVertically = False .Orientation = xlLandscape .Draft = False .PaperSize = xlPaperLetter .FirstPageNumber = xlAutomatic .Order = xlDownThenOver .BlackAndWhite = False .Zoom = False .FitToPagesWide = 1 .FitToPagesTall = 3 .PrintErrors = xlPrintErrorsDisplayed End With End Sub
TO GET SCREEN RESOLUTION
'Add a module to your project (In the menu choose Project -> Add Module, Then click Open) 'Insert this code to the module : Declare Function GetSystemMetrics Lib "user32" (ByVal nIndex As Long) As Long Public Const SM_CXSCREEN = 0 Public Const SM_CYSCREEN = 1 'Insert this code to your form: Private Sub Form_Load() Dim Tmp As String Tmp = GetSystemMetrics(SM_CXSCREEN) & _ "x" & GetSystemMetrics(SM_CYSCREEN) MsgBox (Tmp) End Sub
ANOTHER CODE FOR GET SCREEN RESOLUTION
Public Function ScreenResolution(f As Form) As String Dim iWidth As Integer, iHeight As Integer iWidth = Screen.Width \ Screen.TwipsPerPixelX iHeight = Screen.Height \ Screen.TwipsPerPixelY ScreenRes = iWidth & " X " & iHeight End Function
TO SET ROW HEIGHT AND COLUMN WIDTH IN MILLIMETERS The macros below lets you set row heights and column widths using millimeters as a scale: Sub SetColumnWidthMM(ColNo As Long, mmWidth As Integer) ' changes the column width to mmWidth Dim w As Single If ColNo < 1 Or ColNo > 255 Then Exit Sub Application.ScreenUpdating = False w = Application.CentimetersToPoints(mmWidth / 10) While Columns(ColNo + 1).Left - Columns(ColNo).Left - 0.1 > Columns(ColNo).ColumnWidth = Columns(ColNo).ColumnWidth Wend While Columns(ColNo + 1).Left - Columns(ColNo).Left + 0.1 < Columns(ColNo).ColumnWidth = Columns(ColNo).ColumnWidth Wend End Sub Sub SetRowHeightMM(RowNo As ' changes the row height to If RowNo < 1 Or RowNo > Rows(RowNo).RowHeight = 10) End Sub
w - 0.1 w + 0.1
Long, mmHeight As Integer) mmHeight 65536 Then Exit Sub Application.CentimetersToPoints(mmHeight /
This example macro shows how you can set the row height for row 3 and the column width for column C to 3.5 cm: Sub ChangeWidthAndHeight() SetColumnWidthMM 3, 35 SetRowHeightMM 3, 35 End Sub