gpt4 book ai didi

vba - Excel Vba 宏用于换行、居中、自动调整列和行的大小

转载 作者:行者123 更新时间:2023-12-02 17:42:26 26 4
gpt4 key购买 nike

我试图让这个专栏做一些事情,但是当它开始换行并居中时,它没有这样做......它不会出错,但它不会换行或居中......有什么想法吗?提前!

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

关于vba - Excel Vba 宏用于换行、居中、自动调整列和行的大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42795641/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com