Excel vba开发求助,单步执行与直接执行结果不一致

王小王. 2020-04-24 01:13:27
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
...全文
434 回复 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

5,172

社区成员

发帖
与我相关
我的任务
社区描述
其他开发语言 Office开发/ VBA
社区管理员
  • Office开发/ VBA社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧