A family of Microsoft spreadsheet software with tools for analyzing, charting, and communicating data.
Place all workbooks in a folder, without other workbooks.
Copy the following code into a module in another workbook (not in that folder) and modify/complete it.
When you run the macro, it will prompt the user to select a folder, then loop through the workbooks in the folder, and insert a header row.
Sub SetHeaderRow()
Dim strPath As String
Dim strFile As String
Dim wbk As Workbook
Dim wsh As Worksheet
' Let user select a folder
With Application.FileDialog(msoFileDialogFolderPicker)
If .Show Then
strPath = .SelectedItems(1)
Else
MsgBox "No folder selected", vbInformation
Exit Sub
End If
End With
Application.ScreenUpdating = False
If Right(strPath, 1) <> "" Then
strPath = strPath & ""
End If
' Loop through the Excel workbooks in the folder
strFile = Dir(strPath & "*.xls*")
Do While strFile <> ""
' Open the workbook
Set wbk = Workbooks.Open(Filename:=strPath & strFile, AddToMRU:=False)
' Loop through the worksheets in the workbook
For Each wsh In wbk.Worksheets
' Insert row
wsh.Range("A1").EntireRow.Insert
' Set some values
wsh.Range("A1") = "This"
wsh.Range("B1") = "That"
' ...
wsh.Range("L1") = "Finally"
Next wsh
' Save and close the workbook
wbk.Close SaveChanges:=True
' On to the next
strFile = Dir
Loop
Application.ScreenUpdating = True
End Sub