Dear Sirs,
I've found a macro that can open each files in the folder and I modified it as below. The codes cannot run to the end but only just open one file and stop.
However, if I open the explorer and press F5 to run the codes, it can run to the end successfully.
Would be grateful if someone could give me some guidance.
Thanks in advance.
I've found a macro that can open each files in the folder and I modified it as below. The codes cannot run to the end but only just open one file and stop.
However, if I open the explorer and press F5 to run the codes, it can run to the end successfully.
Code:
Sub AutoImportY()
'
'Hotkey : Ctrl + Shft + Y
'
Dim fsoFile As Object
Dim myPath As String
Dim counter As Long
Application.AskToUpdateLinks = False
Application.DisplayAlerts = False
myPath = ActiveWorkbook.Path & "\"
For Each fsoFile In CreateObject("Scripting.FileSystemObject").GetFolder(myPath).Files
If LCase(fsoFile.Name) Like "*flex*.xl*" Then 'quoted like file should be lower case
counter = counter + 1
Workbooks.Open (myPath & fsoFile.Name)
Run ("'zMacro-Fleks (add Cost Summary sheet).xlsm'!AutoCostSummary")
ActiveWorkbook.Close SaveChanges:=True
End If
Next
Application.ScreenUpdating = True
Application.AskToUpdateLinks = True
Application.DisplayAlerts = True
MsgBox counter & " Flex files added Cost Summary.", , "Done"
End Sub
Would be grateful if someone could give me some guidance.
Thanks in advance.