Logo 
Search:

MS Office Answers

Ask Question   UnAnswered
Home » Forum » MS Office       RSS Feeds
  Question Asked By: Dylan Bouchard   on Dec 28 In MS Office Category.

  
Question Answered By: Bohdana Nonob   on Dec 28

This code will help you to loop thru. all the files in a particular folder,
you need to tune the code as per your requirement

Sub FindXLSFiles()
Dim lFile As Long
With Application.FileSearch
.NewSearch
.FileType = msoFileTypeExcelWorkbooks
.LookIn = "C:\Data"
.SearchSubFolders = False
.Execute SortBy:=msoSortByFileType
If .FoundFiles.Count Then
For lFile = 1 To .FoundFiles.Count
On Error GoTo myerrhand
Workbooks.Open Filename:=.FoundFiles(lFile), UpdateLinks:=0
xbook = ActiveWorkbook.Name
Application.StatusBar = "Now working on " & ActiveWorkbook.FullName
'Here is the line that calls the macro  below, passing the workbook
to it
DoChanges
ActiveWorkbook.Save
Application.DisplayAlerts = False
Windows(xbook).Close

myerrhand:
Windows(ActiveWorkbook.Name).Activate
Next lFile
End If
End With
Application.StatusBar = False
End Sub
'-------------------------------
Sub DoChanges()
With ActiveWorkbook
For Each a In .Worksheets
a.Activate
If ActiveSheet.Name <> "Settings" Then
ActiveSheet.PageSetup.FooterMargin =
Application.InchesToPoints(0.3)
Range("A1:F1").Select
Selection.Merge
With Selection
.WrapText = True
.MergeCells = True
End With
End If
Next
End With
Sheets(1).Select
Application.ScreenUpdating = True

End Sub

Share: 

 

This Question has 8 more answer(s). View Complete Question Thread

 
Didn't find what you were looking for? Find more on advancing date macro Or get search suggestion and latest updates.


Tagged: