页面设置问题
在“打印单个范围”系列问题的最后一个问题中,我在此虚心向知识渊博的读者询问如何将 PageSetup 对象从一个页面复制到另一个页面。
由于您可以简单地 Dest.PageSetup = Source.PageSetup
我必须创建具有相同功能的函数。 缩写形式如下:
Public Sub CopyPageSetup(ByVal Source As Worksheet, ByRef Dest As Worksheet)
With Source.PageSetup
Call SetParam(.AlignMarginsHeaderFooter, Dest.PageSetup.AlignMarginsHeaderFooter)
' etc
Call SetParam(.Zoom, Dest.PageSetup.Zoom)
End With
End Sub
SetParam 很简单:
Public Sub SetParam(ByVal Source As Variant, ByRef Dest As Variant)
If Dest <> Source Then Dest = Source
End Sub
但是,这不会复制页面设置 - 调用此函数后,我立即调用 tmp.PrintPreview (其中 tmp 是临时工作表),输出为就像我从未调用过该函数一样。
这是海市蜃楼吗(它对你有用吗?),如果它不是海市蜃楼,我需要做什么来纠正这个问题?
In what is hopefully the last problem in the "Print An Individual Range" series of questions, I hereby humbly ask the more knowledgable readers how to copy the PageSetup object from one page to another.
Since you can simply Dest.PageSetup = Source.PageSetup
I have had to create function that does the same. An abridge form is below:
Public Sub CopyPageSetup(ByVal Source As Worksheet, ByRef Dest As Worksheet)
With Source.PageSetup
Call SetParam(.AlignMarginsHeaderFooter, Dest.PageSetup.AlignMarginsHeaderFooter)
' etc
Call SetParam(.Zoom, Dest.PageSetup.Zoom)
End With
End Sub
And SetParam is simply:
Public Sub SetParam(ByVal Source As Variant, ByRef Dest As Variant)
If Dest <> Source Then Dest = Source
End Sub
However this does not copy the page setup across - immeadiately after calling this function I call tmp.PrintPreview
(where tmp is a temporary worksheet) and the output is the same as if I had never called the function.
Is this a mirage (does it work for you?) and if it is not a mirage what do I need to do to correct this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我的 Excel 版本(2003)不支持 .AlignMarginsHeaderFooter 属性,但我可以将 Zoom 和 BottomMargin 属性复制到新页面。
My version of Excel (2003) doesn't support the .AlignMarginsHeaderFooter property, but I got the zoom and BottomMargin properties to copy to the new page just fine.