如何使用VBA将页面设置从工作表复制到另一个工作表 [英] How to copy the page setup from worksheets to another using VBA
问题描述
如何使用VBA将页面设置(包括RightHeaderPicture)从工作表复制到另一个工作表?有人可以帮我吗?问候,安东尼·特伦斯
How can I copy the page setup, including the RightHeaderPicture from worksheet to another using VBA? Can someone help me here? Regards, Antony Terrence
推荐答案
有点粗略,但是您会在完成时就明白了!
A bit bare-bones but you will get the idea by the time you have finished!
显然,没有简单的方法可以完整地复制PageSetup对象,因此,假设工作簿已打开,请尝试以下操作:
Apparently there is no easy way to copy the PageSetup object in its entirety so, assuming the workbook is open try the following:
Sub cpyPS()
Dim wsFrom As Worksheet, wsTO As Worksheet
Set wsFrom = Sheets("From")
Set wsTO = Sheets("To")
With wsTO.PageSetup
'there are nearly 50 properties
.AlignMarginsHeaderFooter = wsFrom.PageSetup.AlignMarginsHeaderFooter
.BlackAndWhite = wsFrom.PageSetup.BlackAndWhite
.BottomMargin = wsFrom.PageSetup.BottomMargin
'
'
.LeftMargin = wsFrom.PageSetup.LeftMargin
'
'
.Orientation = wsFrom.PageSetup.Orientation
'
'
.PaperSize = wsFrom.PageSetup.PaperSize
.RightHeaderPicture.Filename = wsFrom.PageSetup.RightHeaderPicture.Filename
.RightMargin = wsFrom.PageSetup.RightMargin
'
'
.TopMargin = wsFrom.PageSetup.TopMargin
'
'
.Zoom = wsFrom.PageSetup.Zoom
End With
End Sub
要考虑的属性的完整列表为在此处提供.
The full list of properties to consider is provided here.
没关系,也许将它作为一个函数编写一次并回发给所有人使用?
Never mind, perhaps write it once as a function and post back for all to use?
如果可以,您可以始终复制整个工作表并重命名.这些属性将像以前一样被采用".
You could always copy the whole sheet and rename it if this is doable for you. The properties will be 'taken across' as it were.
这篇关于如何使用VBA将页面设置从工作表复制到另一个工作表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!