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

轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/55731.html
上一篇:對于鴻蒙的一點見解
