英文:
How to wrap text with auto fit specific table columns?
问题
以下代码用于包装文本并自适应第二和第三列。然而,最后出现了运行时错误 424 "需要对象"。
Set ws = ActiveSheet
Set tbl = ws.ListObjects(2)
With ws
tbl.ListColumns(2).Range.WrapText = True
tbl.ListColumns(2).Range.Rows.AutoFit = True
tbl.ListColumns(3).Range.WrapText = True
tbl.ListColumns(3).Range.Rows.AutoFit = True
End With
英文:
The following code works to wrap text and autofit the 2nd and 3rd column. However, I get a runtime error 424 "object required" at the end.
Set ws = ActiveSheet
Set tbl = ws.ListObjects(2)
With ws
tbl.ListColumns(2).Range.WrapText = True
tbl.ListColumns(2).Range.Rows.AutoFit = True
tbl.ListColumns(3).Range.WrapText = True
tbl.ListColumns(3).Range.Rows.AutoFit = True
End With
</details>
# 答案1
**得分**: 1
[`AutoFit`](https://learn.microsoft.com/en-us/office/vba/api/excel.range.autofit) 是一个方法;移除 `= True`:
```vba
tbl.ListColumns(2).Range.Rows.AutoFit
...
tbl.ListColumns(3).Range.Rows.AutoFit
英文:
AutoFit
is a method; remove the = True
:
tbl.ListColumns(2).Range.Rows.AutoFit
...
tbl.ListColumns(3).Range.Rows.AutoFit
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论