Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Word VBA - Eliminate Floating Object Tables

Tags:

ms-word

vba

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!

like image 389
BlueBerry Avatar asked Jul 07 '15 22:07

BlueBerry


People also ask

What is a floating table in Word?

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.


1 Answers

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
like image 127
Uri Goren Avatar answered Jan 05 '23 03:01

Uri Goren