我有这段代码来设置工作簿中某些工作表的打印区域。我试图设置打印区域,使其适合一页上的每个标签,并且不会将其分成几页。也有人可以帮我处理代码,根据每个标签中相同的单元格值,不在某些选项卡上设置打印区域吗?
spinnerList.add(Html.fromHtml("NO<sub>2</sub>") + "NO2 - maximum 1-hour concentration");
答案 0 :(得分:2)
你快到了。您可以直接遍历工作表,而不必使用计数器引用它们。
这应该让你非常好:)
Sub PrintArea()
Application.ScreenUpdating = False
Dim ws As Worksheet
For Each ws In ActiveWorkbook.Worksheets
Select Case ws.Index
Case Is = 1, 2, 3, 4, 5, 6 'only perform action on first 6 sheets
If ws.Range("A25") = "Yes" Then 'adjust to desired range and indicator
With ws.PageSetup
.PrintArea = ws.Range("A1:Z24").Address
.Orientation = xlLandscape
.FitToPagesWide = 1
.FitToPagesTall = 1
End With
'set print area to only 1 page
With ws
.Activate 'need to activate sheet to view Page Break Preview
ActiveWindow.View = xlPageBreakPreview 'need to view Page Break Preview to drag page breaks
.VPageBreaks(1).DragOff Direction:=xlToRight, RegionIndex:=1 `drag page over so it's just one page
ActiveWindow.View = xlNormalView 'set view back to normal
End With
End If
End Select
Next ws
End Sub