Unfortunately, I can't attach right now either.
I could, once I'm back at my stay - but that'll be tomorrow evening...
My test document is no big deal, it's just some tabbed gibberish I entered..
Hello [tab] jkgh [tab] b [tab] ijg [tab] ig
Aset
Re [tab]
[tab] [tab] Set bvwer
[tab] Se tve uzghrt
Recrcq2c [tab] [tab] Good bye
I copied that stuff three times and add a bit of tabbed gibberish here, deleted some there to check how well the code will swollow different column numbers too.
![[pacman] [pacman] [pacman]](/data/assets/smilies/pacman.gif)
I have also checked, whether there will be a problem, if the tables follow each other directly, without blank line in between - it worked.
The code did NOT work though, after the first table was already converted to a table.
That means: I ran the code, but broke it off after the first table conversion, then re-ran it. THAT did not work.
Just to be on the safe side, here's the entire code with loop and selection.collapse on the right place, that worked with my 4-table-test doc:
Code:
Sub TableIt()
Dim starter As String, ender As String
Dim RanStart As Long, RanEnd As Long
'...
starter = "Hello"
ender = "Good bye"
Selection.HomeKey unit:=wdStory
With Selection.Find
.ClearFormatting
.Text = starter
.MatchWildcards = False
.MatchCase = False
.Execute
End With
Do While Selection.Find.Found
RanStart = Selection.Range.Start
Selection.Collapse wdCollapseEnd
With Selection.Find
.Text = ender
.Execute
End With
RanEnd = Selection.Range.End
Selection.SetRange RanStart, RanEnd
Selection.ConvertToTable vbTab
Selection.Collapse wdCollapseEnd
Selection.MoveRight unit:=wdCharacter, Count:=1
With Selection.Find
.Text = starter
.Execute
End With
Loop
End Sub
I wonder why it doesn't seem to work for you.
I have tested it on Word 2003, but the code does not use any fancy stuff, so it should also run on other versions.
Not sure about 2007 though.
Wait a sec, I DO have Word 2000.... - and it runs just fine there, too...
[navy]"We had to turn off that service to comply with the CDA Bill."[/navy]
- The Bastard Operator From Hell