2016-09-28 109 views
0

我的代碼應該是更新Word文檔中表格的樣式,然後將寬度更改爲17釐米。更改表格的樣式和格式

Sub ConvertTables() 

    Dim tbl As Table 
    For Each tbl In ActiveDocument.Tables 
     tbl.Style = "K2 Table" 
    Next 

    Selection.Tables(1).PreferredWidthType = wdPreferredWidthPoints 
    Selection.Tables(1).PreferredWidth = CentimetersToPoints(17) 
End Sub 

當我運行宏時,它停在第二部分。有時它會在VB查看器中運行,但不會通過Developer運行宏。

這塊VBA有什麼問題?

回答

0

試試這個

Dim tbl As Table 
For Each tbl In ActiveDocument.Tables 
    tbl.Style = "K2 Table" 

    tbl.PreferredWidthType = wdPreferredWidthPoints 
    tbl.PreferredWidth = CentimetersToPoints(17)   
Next 

我猜的第二部分,當你沒有一個表中選擇

+0

是的,你是正確的就不起作用。非常感謝:) –

+0

不客氣!隨意標記爲已回答 – Jbjstam