Hi All,
I am writing a piece of code to open & run macros looping through the files, but every code run individually has a message box at the end for "code was ran without incident". I was wondering whether there is a way to disable this message box so the code can run through multiple files without having to click the space bar? I do not want to remove this message box, because when the individual runs the code in one file it is useful to have the message box there. Also, I have tried to copy the code & rewrite without the message box but this is someone else's code & it is very complex meaning it jumps a lot between different modules for different purposes so it would take a while to go through every sub & repeat but without a message (error prone too). So, I was wondering is there another alternative which I can add into the below code to automatically disable/close message boxes? (screen updating/displays do not work)
Private Sub LoopThroughFiles()
Application.EnableAnimations = False
Application.ScreenUpdating = False
Application.EnableEvents = False
Application.DisplayAlerts = False
Dim xFd As FileDialog
Dim xFdItem As Variant
Dim xFileName As String
Dim ws As Worksheet
Set xFd = Application.FileDialog(msoFileDialogFolderPicker)
If xFd.Show = -1 Then
xFdItem = xFd.SelectedItems(1) & Application.PathSeparator
xFileName = Dir(xFdItem & "*.xlsm*")
Do While xFileName <> ""
With Workbooks.Open(xFdItem & xFileName)
Set ws = ActiveWorkbook.Sheets("Overview")
ws.Cells(1, 4) = Sheet1.Range("a1")
Application.Run "'" & xFileName & "'!SAP"
Application.Run "'" & xFileName & "'!PlayAll"
.Save
.Close
End With
xFileName = Dir
Loop
End If
Application.EnableAnimations = True
Application.ScreenUpdating = True
Application.EnableEvents = True
Application.DisplayAlerts = True
MsgBox "All files successfully updated"
End Sub
Display More