Thread: [Solved] Word VBA Tables
View Single Post
 
Old 05-23-2014, 02:59 AM
macropod's Avatar
macropod macropod is online now Windows 7 32bit Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,467
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

I believe what's in the links (and other threads you could find with a search) are indeed relevant to your problem, but you don't understand it.

Try the following:
Code:
Sub Demo()
Application.ScreenUpdating = False
Dim wdTbl As Table, wdCell As Cell, Rng1 As Range, Rng2 As Range
With ActiveDocument
  For Each wdTbl In .Tables
    For Each wdCell In wdTbl.Range.Cells
      Set Rng1 = wdCell.Range
      Rng1.End = Rng1.End - 1
      If Rng1.Font.Bold = True Then
        Set Rng2 = wdCell.Next.Range
        Rng2.End = Rng2.End - 1
        Select Case Rng1.Text
          Case "Name": Rng2.InsertBefore "<name>": Rng2.InsertAfter "</name>"
          Case "ID.": Rng2.InsertBefore "<ID>": Rng2.InsertAfter "</ID>"
          Case Else
        End Select
      End If
    Next
  Next
End With
Application.ScreenUpdating = True
End Sub
Basically, the above code goes through all tables in the document, looking for cells with 'Name' or 'ID.' as their text, then adds tags (not necessarily xml) before & after whatever's in the next cell.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote