I have a ton of Word documents with somewhat "corrupted" tables. I've been able to automate most of the repair process, but one issue is still beyond me.
Many of the tables are floating objects - when I show the hidden formatting marks, I see an anchor by the table. I can't leave the documents like this, I need to make everything inline.
I do have a segment of code that "fixes" this, but I don't think it is a good solution. By changing the text wrapping from "None" (the default - what I want it to be) to "Around" and back to "None", this gets fixed. The code is,
Selection.Tables(1).Rows.WrapAroundText = True
Selection.Tables(1).Rows.WrapAroundText = False
I'm sure there is a better way to do this. Does anyone know of something that will work? Thanks!
A floating table is a table which is not part of the main text flow in the document but is instead absolutely positioned with a specific size and position relative to non-frame content in the document.
I have no idea why flapping the WrapAroundText
flag solves your problem, VBA has alot of quirks like that.
Automating this method to all of the tables in the document is fairly simple:
Dim i as Integer
For i=1 to Len(ActiveDocument.Tables)
ActiveDocument.Tables(i).Rows.WrapAroundText = True
ActiveDocument.Tables(i).Rows.WrapAroundText = False
Next i
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With