我有一个简单的问题。我有一个excel文件,其发票格式与不同表格中的表格中的大约30个奇数发票详细信息相关联。我已经设计了一个宏来将每次迭代保存为单独的excel文件。但我想要'文件名'自动化。例如,如果我选择打印记录1-15的发票,则文件名应保存为1,2,3,依此类推。现有代码如下 -
Sub PrintForms()
Dim StartRow As Integer
Dim EndRow As Integer
Dim Msg As String
Dim i As Integer
Sheets("Invoice").Activate
StartRow = Range("StartRow")
EndRow = Range("EndRow")
If StartRow > EndRow Then
Msg = "ERROR" & vbCrLf & "The starting row must be less than the ending row!"
MsgBox Msg, vbCritical, APPNAME
End If
For i = StartRow To EndRow
Range("rowindex") = i
If Range("Preview") Then
Dim wb As Workbook
Set wb = Workbooks.Add
ThisWorkbook.Sheets("Invoice").Copy Before:=wb.Sheets(1)
wb.SaveAs "C:\workspace\1. Sem-1 Accounts\macrotest1.xlsx"
Else
ActiveSheet.PrintOut
End If
Next i
End Sub
Sub EditData()
Worksheets("Invoice Format").Activate
Range("A1").Select
End Sub
Sub ReturnToForm()
Worksheets("Invoice").Activate
Range("rowindex").Select
End Sub
End Sub