इस उत्तर के निचले हिस्से में वीबीए सबराउटिन दिखाता है कि यह कैसे करें।
यह वर्तमान चयन का उपयोग करता प्रारंभिक बिंदु के लिए यह गिर पहले इतनी के रूप में बहु खंड चयन के बारे में चिंता करने की जरूरत नहीं करने के लिए:
Selection.Collapse Direction:=wdCollapseStart
यह तो जाँच करता चयन यह एक तालिका के अंदर है यह सुनिश्चित करें कि
If Not Selection.Information(wdWithInTable) Then
MsgBox "Can only run this within a table"
Exit Sub
End If
तालिका को Selection.Tables(1)
का संदर्भ देकर पहुंच योग्य है। नीचे
कोड अवधारणा का एक सरल सबूत जो केवल या तो डालने या एक लंबवत बार मार्कर को हटाने के लिए तालिका की प्रत्येक पंक्ति में शुरू होने वाले कोशिकाओं में से प्रत्येक के लिए टॉगल था।
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
बिल्कुल सही! यह वही है जो मुझे @enifeder की आवश्यकता है: ActiveDocument.Range (0, Selection.Tables (1) .Range.End) .Tables.count – DRC