如何用vba給word表格新增插入行列?


在word 表格中可以插入行列。

如果要用vba給word表格插入行或者列,可以使用如下的代碼:

Sub exceloffice()
    '作者QQ:1722187970,微信:xycgenius,微信公眾號exceloffice
    Dim oDoc As Document
    Set oDoc = Word.ActiveDocument
    Dim oT As Table
    Dim oRow As Row
    Dim oColumn As Column
    With oDoc
            Set oT = .Tables(1)
            With oT
                '設置要在第幾行前面插入行,這里是第2行
                Set oRow = .Rows(2)
                '在第2行前面插入行
                .Rows.Add oRow
                Set oColumn = .Columns(3)
                '在第3列左邊插入一個空列
                .Columns.Add oColumn
            End With
    End With
End Sub

其中Rows.Add方法和Columns.Add后面必須帶具體的某行或某列對象。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM