使用VBA将页面方向设置为横向

技术流评论10,6103阅读模式

使用Excel VBA的过程中,我们又是可能会需要通过宏设置页面方向,比如将页面方向设置为横向。

一般写这样的代码都是用录制宏,然后再把得到的宏代码拿过来套在程序里。可是在录制这个宏的时候,我发现小小一个改变页面设置,居然录出了50多行代码!大部分都是一些打印设置,事实上并无明显的实际作用(或者说根本就没作用,只是将执行时间白白增加了许多)。文章源自原紫番博客-https://www.yuanzifan.com/429.html

而经过简化,使用宏将页面布局从横向改为纵向事实上只需要三行代码:文章源自原紫番博客-https://www.yuanzifan.com/429.html

Sub Macro1()文章源自原紫番博客-https://www.yuanzifan.com/429.html

ActiveSheet.PageSetup.Orientation = 2文章源自原紫番博客-https://www.yuanzifan.com/429.html

End Sub文章源自原紫番博客-https://www.yuanzifan.com/429.html

事实上,只需要修改PageSetup的Orientation属性,就可以完成这个操作。文章源自原紫番博客-https://www.yuanzifan.com/429.html

事实就是酱紫的~文章源自原紫番博客-https://www.yuanzifan.com/429.html 文章源自原紫番博客-https://www.yuanzifan.com/429.html

 最后更新:2013-12-10

发表评论

匿名网友
:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:
确定

拖动滑块以完成验证