我有一张 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
几个问题:
- 它不会用相同的编号打印三次表格
- 我还需要数字以零开头(例如,0001、0002......000n)
有什么解决办法吗?
答案1
你已经声称你只是复制了其他代码,而不是自己做的。如果你继续沿着这条路走下去,你会迷失方向,我建议你真正学习你需要的那几段代码。
此函数演示了如何让数字每 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