Excel Help! // Fit to page : Persistent Header : Bulk
Excel Help! // Fit to page : Persistent Header : Bulk
Author
Discussion

mike_knott

344 posts

255 months

Wednesday 4th April 2018
quotequote all
Haven't done much in VBA for years but I did have the following snippet of code lying around, which was originally written to search for things in multiple files. I am certainly not a programmer and it probably violates every rule of good programming but it might answer your second question about doing things in multiple files.

The first line allows multiple files to be selected, and the next few lines populate an array with each file name. The For...Next fileCounter loop opens each file in turn for the actions to be carried out before the file is closed without saving changes.

Mike...


Sub DoStuffToMultipleFiles()

checkForArray = Application.GetOpenFilename(MultiSelect:=True)

If Not IsArray(checkForArray) Then
If checkForArray = False Then Exit Sub
fileToSearch(1) = checkForArray
Else
ReDim Preserve fileToSearch(UBound(checkForArray))
For cOunter = 1 To UBound(checkForArray)
fileToSearch(cOunter) = checkForArray(cOunter)
Next cOunter
End If

For fileCounter = 1 To UBound(fileToSearch())
Application.StatusBar = "Opening " & fileToSearch(fileCounter)

Workbooks.Open Filename:=fileToSearch(fileCounter)


[Insert other stuff to do here!]

Application.DisplayAlerts = False
ActiveWorkbook.Close
Application.DisplayAlerts = True

Next fileCounter

End Sub()