Excel Vbamacros包装,居中,自动大小列和行

我试图让这个列做一些事情,但是当它把文本和中心它不是这样做…它不会错误,但它不包裹或中心…任何想法? 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 

这对我有效。

事情是, WrapText = TrueColumns.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