VBA小白,准备写一个小功能练手,自动调整Excel中每个sheet的打印设置。
由于打印设置中zoom与FitToPagesWide不能同时设置,当FitToPagesWide = 1时,zoom则为false。
但又需要具体zoom值作为后续判断,故将FitToPagesWide 又改回0,单步执行此句之后可获得zoom值,但直接执行仍然为false,导致无法进行判断。
求大神解惑,代码如下。
Sub 宏1() Application.PrintCommunication = False For p = 1 To Sheets.Count Sheets(p).Activate With ActiveSheet.PageSetup .LeftMargin = Application.InchesToPoints(0.7) .RightMargin = Application.InchesToPoints(0.7) .PaperSize = xlPaperA4 .Orientation = xlPortrait .Zoom = 100 .FitToPagesWide = 1 .FitToPagesWide = 0 .FitToPagesTall = 0 MsgBox (ActiveSheet.PageSetup.Zoom) If .Zoom < 100 Then FileSheet = .Zoom MsgBox (ActiveSheet.PageSetup.Zoom) .Orientation = xlLandscape .FitToPagesWide = 1 .FitToPagesWide = 0 .FitToPagesTall = 0 If .Zoom < 100 Then MsgBox (ActiveSheet.PageSetup.Zoom) .LeftMargin = Application.InchesToPoints(0.25) .RightMargin = Application.InchesToPoints(0.25) End If End If .FitToPagesWide = 1 End With Next p Application.PrintCommunication = True
End Sub

