我有一个结合了多个报告的工作簿。目前,我正在使用一段vba代码来确定根据每个工作表中的单元格值打印哪些工作表。
有没有办法添加到现有代码中,以便将每个工作表设置为每张打印特定次数?例如,使用该工作表上的单元格引用打印sheet1 2次,打印sheet2 1次,依此类推。代码
我到目前为止的打印是:
Sub PrintSheets()
Dim ws As Worksheet
Dim arrWS()
Dim I As Long
For Each ws In Worksheets
If ws.Range("A1") = "print" Then
ReDim Preserve arrWS(I)
arrWS(I) = ws.Name
I = I + 1
End If
Next ws
Sheets(arrWS).PrintOut
End Sub
我尝试了几个不同的项目,但他们每个都看一张纸来确定打印所有内容的次数,而不是让每个页面都有自己特定的副本数量。
答案 0 :(得分:1)
在查看奥马尔的答案和我之前的答案之后,我认为你根本不需要阵列。在单元格A2中放置要在每张纸上打印的份数:
Requested: Ploeh.AutoFixture.Kernel.SeededRequest
Requested: Project.Data.YetAnotherEntity
Created: Project.Data.YetAnotherEntity
Created: Project.Data.YetAnotherEntity
Requested: Ploeh.AutoFixture.Kernel.SeededRequest
Requested: Project.Data.UnrelatedEntity
Created: Project.Data.UnrelatedEntity
Created: Project.Data.UnrelatedEntity
Requested: Ploeh.AutoFixture.Kernel.SeededRequest
Requested: Project.Data.EntityType *<<-- Again? We did this already.*
Requested: Int32 EntityTypeID
Requested: Ploeh.AutoFixture.Kernel.SeededRequest
Requested: System.Int32
Created: 107
Created: 107
Created: 107
Requested: System.Nullable`1[System.Int32] ForeignKey1ID
Requested: Ploeh.AutoFixture.Kernel.SeededRequest
Requested: System.Nullable`1[System.Int32]
Requested: Int32 value
Requested: Ploeh.AutoFixture.Kernel.SeededRequest
Requested: System.Int32
Created: 87
Created: 87
Created: 87
Created: 87
Created: 87
Created: 87
Requested: Int32 Property2ID
Requested: Ploeh.AutoFixture.Kernel.SeededRequest
Requested: System.Int32
Created: 105
Created: 105
Created: 105
Requested: System.DateTime Property3Date
Requested: Ploeh.AutoFixture.Kernel.SeededRequest
Requested: System.DateTime
Created: 5/31/2014 6:50:10 PM
Created: 5/31/2014 6:50:10 PM
Created: 5/31/2014 6:50:10 PM
Requested: Project.Data.OtherEntity OtherEntity *<<!! NO! I stopped you!*
Requested: Ploeh.AutoFixture.Kernel.SeededRequest
Requested: Project.Data.OtherEntity
Requested: Int32 ForeignKey1ID
Requested: Ploeh.AutoFixture.Kernel.SeededRequest
Requested: System.Int32
Created: 168
Created: 168
Created: 168
Requested: System.String Name
Requested: Ploeh.AutoFixture.Kernel.SeededRequest
Requested: System.String
Created: 61eb26e3-890d-4d0d-badd-cd3467c299ed
Created: Name61eb26e3-890d-4d0d-badd-cd3467c299ed
Created: Name61eb26e3-890d-4d0d-badd-cd3467c299ed
Requested: Int32 OtherEntityID
Requested: Ploeh.AutoFixture.Kernel.SeededRequest
Requested: System.Int32
Created: 187
Created: 187
Created: 187
*... and on and on for 750,000 more lines.
答案 1 :(得分:1)
试试这个
Sheets(arrWS).PrintOut Copies:=Range("A2").Value