使用 VBA 遍历工作表中的每个打印页面
Loop Through Each Print Page in Worksheet with VBA
在 VBA 中,如何循环遍历工作簿中每个工作表的每个可打印页面并创建唯一的页脚?我想在整个工作簿中放置 "Page # of Numpages"。我有多个工作表,每个工作表都有多个打印页。
Sub AddPageNumbersToFooters()
Dim ws As Worksheet
Dim numPages as Integer
numPages = 0
For Each ws In ThisWorkbook.Worksheets
With ws.PageSetup
.RightFooter = "Page &P+" & CStr(numPages) & " of "
numPages = numPages + .Pages.Count
End With
Next wsTolStack
For Each ws in ThisWorkbook.Worksheets
With ws.PageSetup
.RightFooter = .RightFooter & CStr(numPages)
End With
Next ws
End Sub
在 VBA 中,如何循环遍历工作簿中每个工作表的每个可打印页面并创建唯一的页脚?我想在整个工作簿中放置 "Page # of Numpages"。我有多个工作表,每个工作表都有多个打印页。
Sub AddPageNumbersToFooters()
Dim ws As Worksheet
Dim numPages as Integer
numPages = 0
For Each ws In ThisWorkbook.Worksheets
With ws.PageSetup
.RightFooter = "Page &P+" & CStr(numPages) & " of "
numPages = numPages + .Pages.Count
End With
Next wsTolStack
For Each ws in ThisWorkbook.Worksheets
With ws.PageSetup
.RightFooter = .RightFooter & CStr(numPages)
End With
Next ws
End Sub