I am trying to update some old code I used years ago to work in a current process. The code below, for every source workbook in the same folder, will open, copy a specific range, paste that range in a summary/master workbook, and close the source document. It loops through this process for all excel documents in the folder, excluding the summary/master.
One change in how this is being used that may or may not be relevant... The source documents are all stored in a MS Teams folder...
One change in how this is being used that may or may not be relevant... The source documents are all stored in a MS Teams folder...
VBA Code:
Private Sub cmdUpdate_Click()
Dim FS, i
Dim PlaceRow As Long
Dim OpenedName As String
Dim DoNotReopenActiveWB_Name As String
Dim DataBook As String
Sheet1.Range("A2:AF1000").ClearContents
Sheet1.Range("BA1:BA1000").ClearContents
Application.DisplayAlerts = False
Application.EnableEvents = False
Application.ScreenUpdating = False
DoNotReopenActiveWB_Name = ActiveWorkbook.Path & "\" & ActiveWorkbook.Name
DataBook = ActiveWorkbook.Name
PlaceRow = 1
Debug.Print DoNotReopenActiveWB_Name
Set FS = Application.FileSearch
With FS
.LookIn = ActiveWorkbook.Path
.Filename = "*.xlsx"
If .Execute Then
For i = 1 To .FoundFiles.Count
If .FoundFiles(i) <> DoNotReopenActiveWB_Name Then
PlaceRow = PlaceRow + 1
Workbooks.Open .FoundFiles(i)
OpenedName = ActiveWorkbook.Name
Workbooks(DataBook).Sheets("Level 1") _
.Range("A" & PlaceRow & ":AI" & PlaceRow).Value = _
Workbooks(OpenedName).Sheets("Level 1") _
.Range("A114:AI114").Value
Workbooks(DataBook).Sheets("Table1") _
.Range("BA" & PlaceRow).Value = .FoundFiles(i)
Workbooks(OpenedName).Close savechanges:=False
End If
Next i
End If
End With
Application.DisplayAlerts = True
Application.EnableEvents = True
Application.ScreenUpdating = True
End Sub
Last edited by a moderator: