2013-02-26 97 views
0

這是我迄今爲止 但即時通訊掙扎SET oCurrentRowVBA的MS Word表格設置行與行光標所在

Sub InsertRow() 

Dim EventDate As String 
Dim oTable As Table 
Dim oCell As Cell 
Dim oCurrentRow As Row 
Dim oNewRow As Row 

If Not Selection.Information(wdWithInTable) Then 
MsgBox "Can only run this within a table" 
Exit Sub 
End If 


Set oTable = ActiveDocument.Tables(1) 
Set oCurrentRow = Selection.Cells(1).RowIndex 


oCurrentRow.Select 
With Selection 
.Collapse Direction:=wdCollapseStart 
.InsertRowsAbove 1 
End With 
' go to inserted row and insert text 

    End Sub 

我猜測我一旦插入上述 oCurrentRow行將引用新插入的行 其中我想在單元格中添加一些文本(1)

回答

0

RowIndex返回一個數字而不是行,因此它不能用於設置行對象。更改

Set oCurrentRow = Selection.Cells(1).RowIndex 

Set oCurrentRow = oTable.Rows(Selection.Cells(1).RowIndex) 

你應該用氣做飯。