Я нашел этот метод в Интернете и думал, что он может быть использован в моем коде, так как у меня есть много страниц для форматирования, и это занимает огромное количество времени:VBA PageSetupXL4M не форматировать должным образом страницы на Excel 2010
Public Sub PageSetupXL4M(Optional LeftHead As String, Optional CenterHead As String, Optional RightHead As String, _
Optional LeftFoot As String, Optional CenterFoot As String, Optional RightFoot As String, Optional LeftMarginInches As String, _
Optional RightMarginInches As String, Optional TopMarginInches As String, Optional BottomMarginInches As String, _
Optional HeaderMarginInches As String, Optional FooterMarginInches As String, Optional PrintHeadings As String, _
Optional PrintGridlines As String, Optional PrintComments As String, Optional PrintQuality As String, Optional CenterHorizontally As String, _
Optional CenterVertically As String, Optional Orientation As String, Optional Draft As String, Optional PaperSize As String, _
Optional FirstPageNumber As String, Optional Order As String, Optional BlackAndWhite As String, Optional Zoom As String)
Const c As String = ","
Dim pgSetup As String
Dim head As String
Dim foot As String
If LeftHead <> "" Then head = "&L" & LeftHead
If CenterHead <> "" Then head = head & "&C" & CenterHead
If RightHead <> "" Then head = head & "&R" & RightHead
If Not head = "" Then head = """" & head & """"
If LeftFoot <> "" Then foot = "&L" & LeftFoot
If CenterFoot <> "" Then foot = foot & "&C" & CenterFoot
If RightFoot <> "" Then foot = foot & "&R" & RightFoot
If Not foot = "" Then foot = """" & foot & """"
pgSetup = "PAGE.SETUP(" & head & c & foot & c & _
LeftMarginInches & c & RightMarginInches & c & _
TopMarginInches & c & BottomMarginInches & c & _
PrintHeadings & c & PrintGridlines & c & _
CenterHorizontally & c & CenterVertically & c & _
Orientation & c & PaperSize & c & Zoom & c & _
FirstPageNumber & c & Order & c & BlackAndWhite & c & _
PrintQuality & c & HeaderMarginInches & c & _
FooterMarginInches & c & PrintComments & c & Draft & ")"
Application.ExecuteExcel4Macro pgSetup
End Sub
Проблема в том, что это вовсе не форматирование страниц (может быть, проблема в том, что я использую Excel 2010?). я называю установки XL4 страницы в этой другой части кода:
Dim Sheets_Select
For Each sheet_select In ActiveWorkbook.Worksheets
sheet_select.Select
With sheet_select
.Cells(1, 1).Font.Bold = True
.Cells(1, 1).Value = "type-no. " & TypeNo
.Cells(1, 1).Characters(Start:=1, Length:=17).Font.FontStyle = "Standard"
.Cells(2, 1).Font.Bold = True
.Cells(2, 1).Value = "specification point: " & SpecName
.Cells(2, 1).Characters(Start:=1, Length:=28).Font.FontStyle = "Standard"
End With
With sheet_select
.Rows.RowHeight = 12
.Columns.ColumnWidth = 3.43
.Columns("A:A").ColumnWidth = 8
.Cells.NumberFormat = "0.0"
.Cells.Font.Name = "Arial"
.Cells.Font.Size = 9
.Cells.HorizontalAlignment = xlCenter
.Columns("A:A").HorizontalAlignment = xlLeft
.Rows("1:9").HorizontalAlignment = xlLeft
End With
'###### L o g o ######
sheet_select.Cells(2, 27).Select
sheet_select.Pictures.Insert(apppath + "\Script\logo.bmp").Select
Selection.ShapeRange.ScaleWidth 0.35, msoFalse, msoScaleFromTopLeft
Selection.ShapeRange.ScaleHeight 0.35, msoFalse, msoScaleFromTopLeft
'###### P a g e S e t u p ######
PageSetupXL4M Orientation:="""xlLandscape""", LeftMarginInches:="""0.6""", RightMarginInches:="""0.6""", TopMarginInches:="""0.6""", BottomMarginInches:="""1""", HeaderMarginInches:="""0.5""", FooterMarginInches:="""0.5""", PaperSize:="""xlPaperA4"""
Application.ExecuteExcel4Macro pgSetup
'.LeftHeader = Header(1, 1)
'.CenterHeader = Header(1, 2)
'.RightHeader = Header(1, 3)
'.LeftFooter = Header(2, 1)
'.CenterFooter = Header(2, 2)
'.RightFooter = Header(2, 3)
Next sheet_select
Спасибо Филипп, я могу спросить вас, если время расчета максимально короткое с XL4 макросами? – Noldor130884
он должен быть закрыт, за исключением проблемы с PageHeadings, как указано в [MS Answers - Excel Macro не изменит информацию заголовка] (http://answers.microsoft.com/en-us/office/forum/office_2010- customize/excel-macro-will-not-change-header-information/43cfb783-9b6e-42cf-b935-4a2752b147a9) –
Я пробовал и пытался ... И похоже, как-то, если я установил application.printcommunication в false, страница будет настроена неправильно :( – Noldor130884