设置每个工作表的份数 [英] Set number of copies per worksheet

查看:157
本文介绍了设置每个工作表的份数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个工作簿结合了多个报告。目前,我正在使用一段vba代码来确定哪些工作表根据每个工作表中的单元格值进行打印。



有没有办法添加现有代码来设置每个工作表,以便每张打印一个特定次数?例如,打印sheet1 2次,打印sheet2 1次,等等,使用该工作表上的单元格引用。代码



到目前为止,我打印的是:

  Sub PrintSheets()
Dim ws As Worksheet
Dim arrWS()
Dim I As Long
For each ws In Worksheets
如果ws.Range(A1)= print然后
ReDim保存arrWS(I)
arrWS(I)= ws.Name
I = I + 1
结束如果
下一个ws

表格(arrWS).PrintOut
End Sub

一对夫妇不同的项目,但他们每个查看一张表,以确定打印的次数,而不是允许每个页面有自己的具体数量的副本。

解决方案

在看了奥马尔的答案和我以前的答案后,我想你根本不需要一个数组。将要打印的份数放在单元格A2中的每张纸上:

  Sub PrintSheets()
Dim ws作为工作表

对于工作表中的每个ws
如果ws.Range(A1)=print然后
ws.PrintOut副本:= ws.Range(A2 ).Value2
End If
下一个ws


End Sub


I have a workbook that combines multiple reports. Currently, I am using a piece of vba code to determine which worksheets are printed based on a cell value in each worksheet.

Is there a way to add to the existing code to set each worksheet to print a specific number of times per sheet? example, print sheet1 2 times, print sheet2 1 time, and so on, using a cell reference on that worksheet. The code

I have for printing so far is:

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

I've tried a couple different items, but they each look to one sheet to determine how many times everything is printed, instead of allowing each page to have its own specific number of copies.

解决方案

After looking at Omar's answer and my previous answer, I think you don't need an array at all. Put the number of copies you want to print on each sheet in Cell A2:

Sub PrintSheets()
Dim ws As Worksheet

For Each ws In Worksheets
    If ws.Range("A1") = "print" Then
        ws.PrintOut Copies:= ws.Range("A2").Value2
    End If
Next ws


End Sub

这篇关于设置每个工作表的份数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆