欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

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

程序员文章站 2024-02-23 19:39:10
...

还有点小问题,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