嘗試實作這個巨集 -每次列印時變更數字。
我目前正在嘗試在列印批次時使用巨集來更改發票號碼。
***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.
.PrintOut 'Print the sheet
End With
Next copynumber
End Sub***
它按原樣工作,但我想列印一批從發票編號 400 開始的發票。
For copynumber = 1 To CopiesCount
到
For copynumber = 400 To CopiesCount
它不起作用。 (此更改是在對鏈接問題中已接受答案的評論中建議的。)
如何更改代碼以指定起始發票編號?
答案1
嘗試這個修改後的程式碼。我添加了兩個新變數(start
和limit
),使此程式碼更容易自訂以列印發票號碼。現在有第二個使用者提示輸入起始發票號碼。limit
根據兩個用戶輸入計算。
Sub PrintCopies_ActiveSheet()
Dim CopiesCount As Long
Dim copynumber As Long
Dim start as Variant, limit 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.
'starting invoice number
start = Application.InputBox("Start sequence at what invoice number?", Type:=1)
'This gives you the ability to cancel the macro by clicking Cancel.
If start = "False" Then
Exit Sub
End If
limit = start + CopiesCount - 1 'last invoice number to print
For copynumber = start To limit
With ActiveSheet
.Range("E1").Value = copynumber 'I assume your invoice number is in cell E1.
.PrintOut 'Print the sheet
End With
Next copynumber
End Sub