VBA/Excel/Access/Word/Excel/Worksheet Print Setting

Материал из VB Эксперт
Версия от 12:47, 26 мая 2010; Admin (обсуждение | вклад) (1 версия)
(разн.) ← Предыдущая | Текущая версия (разн.) | Следующая → (разн.)
Перейти к: навигация, поиск

puts the filename in the right footer

 
     Private Sub Workbook_BeforePrint(Cancel As Boolean)
           Dim myWorksheet As Worksheet
           Dim sFileName As String
           Dim sCompanyName As String
           sCompanyName = Worksheets("Profit").Range("A1").Value
           sFileName = "&F" "Code generating file name
           For Each myWorksheet In ThisWorkbook.Worksheets
           With myWorksheet.PageSetup
              .LeftFooter = sCompanyName
              .CenterFooter = ""
              .RightFooter = sFileName
           End With
           Next myWorksheet
     End Sub



To print a defined area, center horizontally, with 2 rows as titles, in portrait orientation and fitted to page wide and tall - 1 copy

 
Sub PrintRpt3()
    With Worksheets("Sheet1").PageSetup
        .CenterHorizontally = True
        .PrintArea = "$A$3:$F$15"
        .PrintTitleRows = ("$A$1:$A$2")
        .Orientation = xlPortrait
        .FitToPagesWide = 1
        .FitToPagesTall = 1
    End With
    Worksheets("Sheet1").PrintOut
End Sub