0
我发现在互联网上这种方法,并认为这可能会在我的代码中使用,因为我有很多的网页格式,它需要的时间大量的: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 2013-05-08 11:06:44
它应该肯定是接近的,除了页面头部的问题,如[MS Answers - Excel宏不会更改头信息](http://answers.microsoft.com/zh-cn/office/forum/office_2010-定制/ excel宏将不会改变头信息/ 43cfb783-9b6e - 42cf - b935 - 4a2752b147a9) – 2013-05-08 11:23:36
我试过,并尝试过...它看起来像某种方式,如果我将application.printcommunication设置为false,页面将无法正确设置:( – Noldor130884 2013-05-13 15:04:49