0

I have 200 excel sheets that all need the same 5 cells updated from their current content to new content. All will have the same new content.

I am wondering if there is anyway to do this in bulk instead of opening each individual document and doing the updates one by one.

Example:

Document 1, cell B/C/D7 (merged cell) contains a date in DD.MM.YYYY format. I need that date in YYYY.MM.DD format in all 200 documents.

Can this be done using a macro or something?

4

1 回答 1

2

最简单的方法确实是使用 VBA 来完成。您可以将所有文件放在一个目录中,然后使用来循环浏览所有文件,应用您的更改。

对于您提到的情况,假设您需要对Sheet1需要运行的每个工作簿的工作表进行更改wbResults.Worksheets("Sheet1").Range("B7").NumberFormat = "YYYY.MM.DD"

Sub RunCodeOnAllXLSFiles()
Dim lCount As Long
Dim wbResults As Workbook
Dim wbCodeBook As Workbook


Application.ScreenUpdating = False
Application.DisplayAlerts = False
Application.EnableEvents = False

On Error Resume Next
    Set wbCodeBook = ThisWorkbook
        With Application.FileSearch
            .NewSearch
            'Change path to suit
            .LookIn = "C:\MyDocuments\TestResults"
            .FileType = msoFileTypeExcelWorkbooks
            'Optional filter with wildcard
            '.Filename = "Book*.xls"
                If .Execute > 0 Then 'Workbooks in folder
                    For lCount = 1 To .FoundFiles.Count 'Loop through all
                        'Open Workbook x and Set a Workbook variable to it
                        Set wbResults = Workbooks.Open(Filename:=.FoundFiles(lCount), UpdateLinks:=0)

                        'DO YOUR CODE HERE
                         wbResults.Worksheets("Sheet1").Range("B7").NumberFormat = "YYYY.MM.DD"
                        wbResults.Close SaveChanges:=True
                    Next lCount
                End If
        End With
On Error GoTo 0
Application.ScreenUpdating = True
Application.DisplayAlerts = True
Application.EnableEvents = True
End Sub
MsoFileType can be one
于 2012-12-06T09:54:44.590 回答