![]() |
|
#1
|
|||
|
|||
|
In a word document I need to tag “AAA” at the beginning of the table (Above to the Table) and “BBB” at the end of the table (Next to the end of a table).
After running a macro at the beginning of the table it should get tagged as “AAA” then it should be Ask for confirmation at the end of the table as “wish you want to continue the table “Yes” or “No”. if we select yes then it should be move to the next table and again it should be asked for confirmation Yes or No until we select No. if we select No then it should be tagged as “BBB” at the ending of the table. Although I'm not quite sure if we could automate this work or not, if it doesn't seem realistic, please excuse me… If it works well, I can modify the code and tagged remaining tables in a document. I need to tag all the tables in a document based on the table header presentation, there will be a minimum of 40 tables in a document to tag this manually… I really appreciate your help and my sincere gratitude goes out to you for your support. ![]() Please find the attachment for a sample doc. Doc Type: ".docx" , ".rtf" |
|
#2
|
||||
|
||||
|
Try this code
Code:
Sub TagTables()
Dim aTbl As Table, bSkip As Boolean, iCount As Integer, i As Integer
iCount = ActiveDocument.Tables.Count
For i = 1 To iCount
Set aTbl = ActiveDocument.Tables(i)
aTbl.Select
If Not bSkip Then
aTbl.Range.Previous(Unit:=wdCharacter, Count:=1).InsertBefore vbCr & "AAA"
bSkip = MsgBox("Yes to Extend tag, No to close tag", vbYesNo) = vbYes
If Not bSkip Then aTbl.Range.Next(Unit:=wdCharacter, Count:=1).InsertBefore "BBB" & vbCr
Else
bSkip = MsgBox("Yes to Extend tag, No to close tag", vbYesNo) = vbYes
If bSkip = False Then
aTbl.Range.Next(Unit:=wdCharacter, Count:=1).InsertBefore "BBB" & vbCr
End If
If i = iCount - 1 Then bSkip = False
End If
Next i
End Sub
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia |
|
#3
|
|||
|
|||
|
Hi,
It is much appreciated that you responded so quickly... Its working but the looping was continuing to all the tables in a document even if we select “NO” or “YES” If we select "YES" it should move to the next table and if we select “No” it should stop looping & tagged “BBB” at the end of that table but here if we select “Yes or No” it was looping all the tables in a document & tagging to the tables. Tagged AAA at the beginning of the active table, then if we select "Yes" It should moved to next table, again if we select "Yes" it should moved to next table, if we select "No" then it should stop moving to next table and tagged BBB at the end of that table. It would be appreciated if you reviewed the code once and fixing the issue. |
|
#4
|
||||
|
||||
|
Quote:
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia |
|
#5
|
|||
|
|||
|
Hi
Sorry for inconvenience caused to you, I need to tag all tables in a document but tagging text is different. If i get a exact code I can modify the tagging text based on a table headers. I will change a tagging text based on the requirement. This is actual requirement. Tagged AAA at the beginning of the active table, then if we select "Yes" It should moved to next table, again if we select "Yes" it should moved to next table, if we select "No" then it should stop moving to next table and tagged BBB at the end of that table. Please find test document in a attachment. Thanks.... |
|
#6
|
|||
|
|||
|
Quote:
Not all the tables in a documents, tagged AAA on the active table beginning and it should move to next table based on the input Yes or No, if YES means move to next table and NO means it will not move to next table and tagged BBB at the end of that table. I would appreciate if you could review the code once based on the above requirements. Despite my best efforts, I could not modify the code. I greatly appreciate you helping me and I thank you very much... |
|
#7
|
|||
|
|||
|
|
|
#8
|
|||
|
|||
|
This is actual requirement.
Tagged AAA at the beginning of the active table, then if we select "Yes" It should moved to next table, again if we select "Yes" it should moved to next table, if we select "No" then it should stop moving to next table and tagged BBB at the end of that table. Please find test document in a attachment. Please modify the above code. I have posted this in the below forum and would like to modify the code to suit my needs but dont seem to be getting any responses. Tagging This could be because of the previous post being unclear. I would appreciate if you could review the code once based on the above requirements. Despite my best efforts, I could not modify the code. I greatly appreciate you helping me and I thank you very much... |
|
#9
|
|||
|
|||
|
HI,
Am getting a " run time error 5941:", (The requested member of the collection does not exists.) This is actual requirement. Tagged AAA at the beginning of the active table, then if we select "Yes" It should moved to next table, again if we select "Yes" it should moved to next table, if we select "No" then it should stop moving to next table and tagged BBB at the end of that table. Could you plese review the code once and do the needful. Code:
Sub Text_Insert()
Dim i As Long, j As Long
Dim rng As Range
If Selection.Information(wdWithInTable) = False Then
MsgBox "The selection is not inside a table."
Exit Sub
End If
With ActiveDocument
For i = 1 To .Tables.Count
If Selection.Range.Start > .Tables(i).Range.Start And Selection.Range.End < .Tables(i).Range.End Then
Exit For
End If
Next i
Set rng = .Tables(i).Range
rng.Collapse wdCollapseStart
rng.MoveStart wdCharacter, -1
rng.InsertBefore vbCr & "AAA"
For j = i + 1 To .Tables.Count
If MsgBox("Do you wish to insert the End tag after this table", vbQuestion + vbYesNo) = vbYes Then
Set rng = .Tables(j).Range
rng.Collapse wdCollapseEnd
rng.InsertAfter "BBB" & vbCr
Exit For
End If
Next j
End With
End Sub
|
|
#10
|
||||
|
||||
|
Assuming you want to start from the current selection position.
Code:
Sub TagTables2()
Dim aTbl As Table, bSkip As Boolean, iCount As Integer, i As Integer, aRng As Range
Set aRng = ActiveDocument.Range(Selection.Start, ActiveDocument.Range.End)
bSkip = False
iCount = aRng.Tables.Count
For Each aTbl In aRng.Tables
i = i + 1
aTbl.Select
If bSkip = False Then aTbl.Range.Previous(Unit:=wdCharacter, Count:=1).InsertBefore vbCr & "AAA"
bSkip = MsgBox("Yes to Extend tag, No to stop and close tag", vbYesNo) = vbYes
If i = iCount Or Not bSkip Then
aTbl.Range.Next(Unit:=wdCharacter, Count:=1).InsertBefore "BBB" & vbCr
Exit For
End If
Next aTbl
End Sub
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia |
|
| Tags |
| tagging |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Tagging Misspell words | ranjan | Word VBA | 3 | 08-18-2021 06:02 AM |
| Word to xml tagging macro | ganesang | Word VBA | 0 | 03-19-2019 04:10 AM |
Need macro for XML tagging in word doc
|
ganesang | Word VBA | 4 | 03-13-2019 02:39 AM |
Code to find a named (bookmarked?) table, replicate a row or table, and delete a specified table.
|
kevinbradley57 | Word VBA | 9 | 09-21-2017 04:58 PM |
| Macro for tagging and rearranging selected text for revision | caotico | Word VBA | 0 | 03-28-2012 06:35 PM |