I have the following code below to export files
When running the macro, the current workbook is being closed
I would like my code amended so that the current workbook is not closed
It would be appreciated if someone could kindly assist me
When running the macro, the current workbook is being closed
I would like my code amended so that the current workbook is not closed
It would be appreciated if someone could kindly assist me
Code:
Sub Export_Files()
With Application
.ScreenUpdating = False
.DisplayAlerts = False
.CutCopyMode = False
End With
Dim ws As Worksheet
Dim rngCell As Range
Dim fPATH As String: fPATH = "C:\pull\"
Dim FSO As Object: Set FSO = CreateObject("Scripting.FileSystemObject")
Dim FLD As Object: Set FLD = FSO.GetFolder(fPATH)
Dim SubFLDRS As Object: Set SubFLDRS = FLD.SubFolders
Dim SubFLD As Object
Dim wbData As Workbook
Set ws = ThisWorkbook.Sheets("Workbooks")
Application.ScreenUpdating = False
On Error Resume Next
For Each SubFLD In SubFLDRS
For Each rngCell In ws.Range("A1:A" & ws.Cells(ws.Rows.Count, 1).End(xlUp).Row)
Set wbData = Workbooks.Open(SubFLD & "\" & rngCell.Value)
'Application.Run ("'" + rngCell.Value + "'!" + Workbooks(rngCell.Value).Sheets("workbooks").[d1].Value) 'run macros
Application.Run ("'" + rngCell.Value + "'!" + ThisWorkbook.Sheets("workbooks").[d1].Value)
wbData.Close 'close the file
Next rngCell
Next SubFLD
With Application
.ScreenUpdating = True
.DisplayAlerts = True
.CutCopyMode = False
End With
End Sub