Sub AdjustRowHeightInAllExcelFiles()
Dim folderPath As String
folderPath = "C:\Your\Folder\Path" ' フォルダパスを指定してください
ProcessFolder folderPath
End Sub
Sub ProcessFolder(ByVal folderPath As String)
Dim fileSystem As Object
Dim folder As Object
Dim file As Object
Dim subfolder As Object
Set fileSystem = CreateObject("Scripting.FileSystemObject")
Set folder = fileSystem.GetFolder(folderPath)
For Each file In folder.Files
If LCase(Right(file.Name, 5)) = ".xlsx" Or LCase(Right(file.Name, 4)) = ".xls" Then
AdjustRowHeight file.Path
End If
Next file
For Each subfolder In folder.Subfolders
ProcessFolder subfolder.Path
Next subfolder
End Sub
Sub AdjustRowHeight(ByVal filePath As String)
Dim wb As Workbook
Dim ws As Worksheet
Dim rowHeight As Double
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Set wb = Workbooks.Open(filePath)
For Each ws In wb.Worksheets
With ws.Rows(2)
.AutoFit
rowHeight = .RowHeight
.RowHeight = rowHeight + 10
End With
ws.Range("A1").Select
Next ws
wb.Save
wb.Close
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub
Register as a new user and use Qiita more conveniently
- You get articles that match your needs
- You can efficiently read back useful information
- You can use dark theme