页面设置问题

发布于 2024-07-26 09:19:47 字数 798 浏览 2 评论 0原文

在“打印单个范围”系列问题的最后一个问题中,我在此虚心向知识渊博的读者询问如何将 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

青春有你 2024-08-02 09:19:47

我的 Excel 版本(2003)不支持 .AlignMarginsHeaderFooter 属性,但我可以将 Zoom 和 BottomMargin 属性复制到新页面。

Public Sub CopyPageSetup(ByVal Source As Worksheet, ByRef Dest As Worksheet)
   With Dest.PageSetup
        .Zoom = Source.PageSetup.Zoom
        .BottomMargin = Source.PageSetup.BottomMargin
   End With
End Sub

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.

Public Sub CopyPageSetup(ByVal Source As Worksheet, ByRef Dest As Worksheet)
   With Dest.PageSetup
        .Zoom = Source.PageSetup.Zoom
        .BottomMargin = Source.PageSetup.BottomMargin
   End With
End Sub
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文