不管接下来发生什么事,你都不能停止前进

Excel VBA修改不同文件簿sheet页名字

还有点小问题,EXCEL.exe这个进程会一直占用一个文件,很奇怪,如果有知道的大神,欢迎评论补充

这个是统一更改为“Sheet1”这个名字

Private Function GetDirectory()
    Dim fd As FileDialog
    Set fd = Application.FileDialog(msoFileDialogFolderPicker)
    With fd
        If .Show = -1 Then
            GetDirectory = .SelectedItems(1)
        Else
            GetDirectory = ""
        End If
    End With
End Function
Sub ModifySheetName()
    Dim vFiles As Variant
    Dim nIndex As Integer
    Dim wkb As Workbook
    Dim TotalFiles As Integer
     
    Application.DisplayAlerts = False
    vFiles = Application.GetOpenFilename(FileFilter:="Excel工作簿(*.xls*),*.xls*", _
    Title:="选择待转换的文件", MultiSelect:=True)
    If Not IsArray(vFiles) Then Exit Sub
    TotalFiles = UBound(vFiles)
    For nIndex = 1 To TotalFiles
        Set wkb = GetObject(vFiles(nIndex))
        With wkb
            Windows(.Name).Visible = True
            .Sheets(ActiveSheet.Name).Name = "Sheet1"
            .Close SaveChanges:=True
        End With
        Set wkb = Nothing
    Next nIndex
    Application.DisplayAlerts = True
    MsgBox "修改完成!共计" & TotalFiles & "个文件"
End Sub
posted @ 2019-11-25 15:33  普罗旺斯_S  阅读(1179)  评论(0编辑  收藏  举报