|
楼主 |
发表于 2024-6-22 17:05
|
显示全部楼层
Sub 批量AutoFitAll()
Application.ScreenUpdating = False
Dim sh As String
Dim MyPath, MyName, AWbName
Dim mysheet As Worksheet
MyPath = ActiveWorkbook.Path
MyName = Dir(MyPath & "\" & "*.xls")
AWbName = ActiveWorkbook.Name
Num = 0
Do While MyName <> ""
If MyName <> AWbName Then
Set wb = Workbooks.Open(MyPath & "\" & MyName)
Num = Num + 1
sh = ActiveSheet.Name
For Each mysheet In ActiveWorkbook.Worksheets
mysheet.Activate
Application.ScreenUpdating = False
Cells.EntireRow.AutoFit
For i = 1 To ActiveSheet.UsedRange.Rows(ActiveSheet.UsedRange.Rows.Count).Row
If Application.WorksheetFunction.CountA(Rows(i)) > 0 Then
Rows(i).RowHeight = Rows(i).RowHeight + 4
End If
Next i
Application.ScreenUpdating = True
ActiveWorkbook.Save
Next mysheet
Sheets(sh).Select
WbN = WbN & Chr(13) & wb.Name
wb.Close False
End If
MyName = Dir
Loop
MsgBox "共调整" & Num & "个工作薄下全部工作表的行高和列宽。如下:" & Chr(13) & WbN, vbInformation, "提示"
Application.ScreenUpdating = True
End Sub
|
|