如何使用自动调整特定表列来包装文本?

huangapple go评论97阅读模式
英文:

How to wrap text with auto fit specific table columns?

问题

以下代码用于包装文本并自适应第二和第三列。然而,最后出现了运行时错误 424 "需要对象"。

  1. Set ws = ActiveSheet
  2. Set tbl = ws.ListObjects(2)
  3. With ws
  4. tbl.ListColumns(2).Range.WrapText = True
  5. tbl.ListColumns(2).Range.Rows.AutoFit = True
  6. tbl.ListColumns(3).Range.WrapText = True
  7. tbl.ListColumns(3).Range.Rows.AutoFit = True
  8. 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.

  1. Set ws = ActiveSheet
  2. Set tbl = ws.ListObjects(2)
  3. With ws
  4. tbl.ListColumns(2).Range.WrapText = True
  5. tbl.ListColumns(2).Range.Rows.AutoFit = True
  6. tbl.ListColumns(3).Range.WrapText = True
  7. tbl.ListColumns(3).Range.Rows.AutoFit = True
  8. End With
  9. </details>
  10. # 答案1
  11. **得分**: 1
  12. [`AutoFit`](https://learn.microsoft.com/en-us/office/vba/api/excel.range.autofit) 是一个方法;移除 `= True`:
  13. ```vba
  14. tbl.ListColumns(2).Range.Rows.AutoFit
  15. ...
  16. tbl.ListColumns(3).Range.Rows.AutoFit
英文:

AutoFit is a method; remove the = True:

  1. tbl.ListColumns(2).Range.Rows.AutoFit
  2. ...
  3. tbl.ListColumns(3).Range.Rows.AutoFit

huangapple
  • 本文由 发表于 2023年7月28日 02:15:16
  • 转载请务必保留本文链接:https://go.coder-hub.com/76782441.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定