【发布时间】:2017-12-05 00:24:58
【问题描述】:
我正在尝试为公司的每个部门打印一份 Excel 报告,以获取一份包含其下方部分的附录报告的报告。 IE。人力资源部下设招聘、人员配备、合规、包容和多元化、领导力发展等部门。
我希望报告有静态页面,然后是该部门每个部分的四个动态页面。现在,当我运行代码时,只打印/生成一个部分。
Sub GenerateReports()
Dim intRowDiv as Integer
Dim intRowSec as Integer
intRowDiv = 13
intRowSec = 13
Do While Sheets("LOOKUP_VALUES").Cells(2,2).Value = Sheets("LOOKUP_VALUES").Cells(intRowDiv,1).Value
Application.Calculate
'file naming
tempFileName = Sheets("LOOKUP_VALUES").Cells(7,2).Value & " - CLIMATE.pdf"
tempFileName = Replace(tempFileName, "/", "_")
tempFileName = Replace(tempFileName, "\", "_")
tempFileName = Replace(tempFileName, "&", "_")
tempFileName = Replace(tempFileName, ":", "_")
'Select Static Pages
Sheets(Array("2018 CoverPage", "intro", "table of contents", "division snapshot", "engagement snapshot", "action planning", "resources", "branch TOC", "branch intro")).Select
'Select Dynamic Pages
Sheets(2018 CoverPage").Activate
Do While Sheets("LOOKUP_VALUES").Cells(intRowSec, 4).Value <> ""
Sheets("LOOKUP_VALUES").Cells(8,2).Value = Sheets("LOOKUP_VALUES").Cells(intRowSec,4).Value
Sheets(Array("2018 Page10", "2018 Page11", "2018 Page12", "2018 Page13")).Select
'print to local location on comp
tempFileName = "C:\Users\sslattery\Documents\clim_reports\reports\" & TempFileName
'print full
ActiveSheet.ExportAsFixedFormat Type:xlTypePDF, Filename:= _
tempFileName _
, Quality:=xlQUalityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=False
'next section
intRowSec = IntRowSec + 1
Loop
'next division
intRowDiv = intRowDiv + 1
Loop
End Sub
【问题讨论】:
-
您的工作簿样本可能会有所帮助,您可能已经知道 Sheets(2018 CoverPage").Activate 缺少初始“,您也正在激活 Sheets 并选择它们,但这可以在没有任何激活或选择,我不理解的是 Sheet Lookup_values 的布局......