循环另存为

问题描述 投票:0回答:1

我有一些代码试图在循环中执行,因此它会保存位于单元格列表中的具有不同名称的文件

我使用了下面的代码。它按预期保存,但现在我不知道如何让它继续下降到“E5”

Private Sub Save_Click()
Dim FileName As String
    Dim Path As String
    Application.DisplayAlerts = False
    Path = "p:"
    FileName = Sheet10.Range("E4").Value & ".xlsx"
    ActiveWorkbook.SaveAs Path & FileName, xlOpenXMLWorkbook
    Application.DisplayAlerts = True

End Sub
excel vba list save-as
1个回答
0
投票
  • 根据需要在
    For
    子句中更改开始值和结束值
Private Sub Save_Click()
    Dim FileName As String
    Dim Path As String, i As Long
    Application.DisplayAlerts = False
    Path = "p:"
    For i = 4 To 10 ' modify as needed
        FileName = Sheet10.Range("E" & i).Value & ".xlsx"
        ActiveWorkbook.SaveAs Path & FileName, xlOpenXMLWorkbook
    Next
    Application.DisplayAlerts = True
    
End Sub
© www.soinside.com 2019 - 2024. All rights reserved.