Bu yanıtın altındaki VBA alt yordamı, bunun nasıl yapılacağını gösterir.
çok kademeli seçimleri konusunda endişelenmenize gerek yok siz olarak böylece başlangıç noktasına geri çöken, geçerli seçimi kullanır
:
Selection.Collapse Direction:=wdCollapseStart
Daha sonra seçim bir tabloda içeride sağlamak için kontrol eder
If Not Selection.Information(wdWithInTable) Then
MsgBox "Can only run this within a table"
Exit Sub
End If
Tablo, Selection.Tables(1)
'a başvurarak erişilebilir.
Aşağıdaki kod sadece takmak veya dikey bir çubuk işareti silme ya tablonun her satırda başlayan hücrelerin her konum değiştirir kavramının basit bir kanıtı.
Sub VertBar()
' Collapse the range to start so as to not have to deal with '
' multi-segment ranges. Then check to make sure cursor is '
' within a table. '
Selection.Collapse Direction:=wdCollapseStart
If Not Selection.Information(wdWithInTable) Then
MsgBox "Can only run this within a table"
Exit Sub
End If
' Process every row in the current table. '
Dim row As Integer
Dim rng As Range
For row = 1 To Selection.Tables(1).Rows.Count
' Get the range for the leftmost cell. '
Set rng = Selection.Tables(1).Rows(row).Cells(1).Range
' For each, toggle text in leftmost cell. '
If Left(rng.Text, 2) = "| " Then
' Change range to first two characters and delete them. '
rng.Collapse Direction:=wdCollapseStart
rng.MoveEnd Unit:=wdCharacter, Count:=2
rng.Delete
Else
' Just insert the vertical bar. '
rng.InsertBefore ("| ")
End If
Next
End Sub
Mükemmel! Bu tam olarak ihtiyacım olan şey @enifeder: ActiveDocument.Range (0, Selection.Tables (1) .Range.End) .Tables.count – DRC