我试图让这个专栏做一些事情,但是当它包装文本和中心时它不会这样做......它没有错误,但它并没有包裹或中心...任何想法? ty提前!
Sub Resize_Columns_And_Rows_No_Header()
'
'Resize_Columns_And_Rows Macro
'
'Declaration
Dim wkSt As String
Dim wkBk As Worksheet
Dim temp As Variant
Dim lastCol As Long
wkSt = ActiveSheet.Name
' This Loops Through All Sheets
For Each wkBk In ActiveWorkbook.Worksheets
On Error Resume Next
wkBk.Activate
lastCol = wkBk.Cells(1, Columns.Count).End(xlToLeft).Column
'This is only needed if you are wrapping the text
wkBk.Rows.WrapText = True
'This is to center align all rows
wkBk.Rows.VerticalAlignment = xlCenter
' Resize Columns
wkBk.Columns.EntireColumn.AutoFit
' Resize Rows
wkBk.Rows.EntireRow.AutoFit
Next wkBk
Sheets(wkSt).Select
End Sub
答案 0 :(得分:3)
这对我有用。
但事情是, WrapText = True 和 Columns.EntireColumn.AutoFit ,彼此矛盾。
Sub Resize_Columns_And_Rows_No_Header2()
Dim currentSheet As Worksheet
Set currentSheet = ActiveSheet
Dim sheet As Worksheet
For Each sheet In ActiveWorkbook.Worksheets
With sheet
With .Cells.Rows
.WrapText = True
.VerticalAlignment = xlCenter
.EntireRow.AutoFit
End With '.Cells.Rows
.Columns.EntireColumn.AutoFit
End With 'sheet
Next sheet
currentSheet.Activate
End Sub
顺便问一下,你还需要一个:
.HorizontalAlignment = xlCenter