vba调整word中表格每列列宽为不同的厘米宽度
时间: 2023-04-06 16:01:42 浏览: 160
可以使用VBA代码来调整Word中表格每列的列宽为不同的厘米宽度。具体的代码如下:
Sub SetTableColumnWidth()
Dim tbl As Table
Dim col As Column
Set tbl = Selection.Tables(1)
tbl.AutoFitBehavior (wdAutoFitFixed)
tbl.AllowAutoFit = False
tbl.PreferredWidthType = wdPreferredWidthPoints
tbl.PreferredWidth = InchesToPoints(6)
For Each col In tbl.Columns
Select Case col.Index
Case 1
col.Width = CentimetersToPoints(2)
Case 2
col.Width = CentimetersToPoints(3)
Case 3
col.Width = CentimetersToPoints(4)
Case 4
col.Width = CentimetersToPoints(5)
End Select
Next col
End Sub
这段代码会将选中的表格的自适应行为设置为固定宽度,然后将表格的首选宽度设置为6英寸。接着,使用Select Case语句来为每一列设置不同的宽度,其中Case后面的数字表示列的索引,CentimetersToPoints函数用于将厘米转换为磅。
相关推荐
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![pptx](https://img-home.csdnimg.cn/images/20210720083543.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)