Excel宏打印3页相同的数字,然后递增


-1

我有一张excel表来打印一组3页,我用它来制作时间表。我需要某种宏,它可以在每三页打印后更改数字。所以,前三张是0001,接下来是三张0002接下来的三张0003,等等。

如果可能的话,我需要能够从我离开的地方开始。这是我到目前为止所尝试的:

Sub PrintCopies_ActiveSheet()

Dim CopiesCount As Long
Dim copynumber As Long

CopiesCount = Application.InputBox("How many copies do you want?", Type:=1)
'Now the program wants you to input how many pages you like to print.
'You can input 100 here.

For copynumber = 1 To CopiesCount
With ActiveSheet
   .Range("E1").Value = copynumber 'I assume your invoice number is in cell E1.
   For i = 1 To 3
    .PrintOut 'Print the sheet
End With
Next copynumber
End Sub

几个问题:

  1. 它不会使用相同的数字打印三次
  2. 我还需要将数字设为前导零(例如,0001,0002 ... 000n)

有解决方案吗


找到并编辑了一下
Tetsuo_and_Youth 2016年

2
看起来你刚从superuser.com/questions/203892 / ... 复制代码......你edited it a bit好吗?你能解释一下你试图让它运转起来所以我们可以看出它出了什么问题吗?
戴夫

Answers:


0

您已声明自己刚刚复制了其他代码而未自行完成。如果你沿着这条路走下去,你会迷路,我建议你真正学习你需要的小代码。

此函数演示如何获得每3次递增的数字以及如何添加前导零。我假设,根据你的例子(你写的地方(eg, 0001, 0002 ... 000n)),你总是希望前面有3个零。

Sub doThis()

Dim page As Integer
page = 1

Dim pageToUse As String
pageToUse = "000" & page

Dim copyNumber As Integer
Dim copiesCount As Integer
copiesCount = 5

For copyNumber = 1 To copiesCount

    If copyNumber Mod 4 = 0 Then     'needs to be 4 as you start with 1
        pageToUse = "000" & page + 1
    End If

Next copyNumber

End Sub
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.