我希望打印一份excel文档,其中每张未隐藏的工作表都有相关的页码,这样当我打印时,页码从第一页的1开始,第二页的第二页,依此类推。
注意:此处还隐藏了一些隐藏的工作表,使得页码必须仅取决于未隐藏的工作表。
虽然使用下面的代码,但当我选择所有工作表并打印活动工作表时,页码不会从一个工作表更改为另一个工作表,但对于每个工作表而言等于一个工作表。
关于如何解决这个问题的任何想法???
Sub headersfooters()
Dim index As Integer
Dim ws As Worksheet
index = wsVolumes.Range("k4")
Select Case index
Case Is = 1
For Each ws In ActiveWorkbook.Worksheets
ws.Visible
ws.PageSetup.RightHeader = "French"
ws.PageSetup.RightFooter = "&P"
Next ws
End
Case Else
For Each ws In ActiveWorkbook.Worksheets
ws.PageSetup.RightHeader = "English"
ws.PageSetup.RightFooter = "&P"
Next ws
End
End Select
End Sub
谢谢!
答案 0 :(得分:0)
考虑使用ws.PageSetup.FirstPageNumber吗?
Sub headersfooters()
Dim index As Integer
Dim ws As Worksheet
Dim n As Integer
index = wsVolumes.Range("k4")
Select Case index
Case Is = 1
For Each ws In ActiveWorkbook.Worksheets
ws.Visible
ws.PageSetup.RightHeader = "French"
ws.PageSetup.RightFooter = "&P"
n = n + 1
ws.PageSetup.FirstPageNumber = n
Next ws
Case Else
For Each ws In ActiveWorkbook.Worksheets
ws.PageSetup.RightHeader = "English"
ws.PageSetup.RightFooter = "&P"
n = n + 1
ws.PageSetup.FirstPageNumber = n
Next ws
End Select
End Sub