将每张纸保存为原始名称

时间:2019-04-13 18:51:13

标签: excel vba

我有以下代码,其中我将工作表智能文件保存在prn中

在保存文件时,我不想给文件起名字,我只想用其原始名称保存每个工作表(因此,工作表名称raj,taj,bazz。它们全都用其原始名称保存。

Sub CONVERT()
    Dim vcounter As Long
    Dim ws As Worksheet

    For Each ws In Sheets
        ws.Activate

        vcounter = 2
        While Range("A" & vcounter).Value <> ""
            Range("a" & vcounter).Value = Range("a" & vcounter).Value + 1
            vcounter = vcounter + 1
        Wend

        Application.DisplayAlerts = False
        ActiveSheet.SaveAs Filename:="D:\birla soft\apache.prn"
     Next ws
End Sub

1 个答案:

答案 0 :(得分:1)

此代码已经过测试,并且保存了一个文件名,其文件名为ActiveSheet,扩展名相同:

ActiveSheet.SaveAs Filename:="D:\birla soft\" & ActiveSheet.Name

如果您需要将其保存为其他扩展名,请改用以下代码:

ActiveSheet.SaveAs Filename:="D:\birla soft\" & ActiveSheet.Name & ".prn"

在代码中,如果您需要保存每个工作表的名称,只需将ActiveSheet变量更改为ws,如下所示:

Sub CONVERT()
    Dim vcounter As Long
    Dim ws As Worksheet

    For Each ws In Sheets
        ws.Activate

        vcounter = 2
        While Range("A" & vcounter).Value <> ""
            Range("a" & vcounter).Value = Range("a" & vcounter).Value + 1
            vcounter = vcounter + 1
        Wend

        Application.DisplayAlerts = False
        ws.SaveAs Filename:="D:\birla soft\" & ws.Name & ".prn"
     Next ws
End Sub