Word 2013 - previous macro building table not working - TechRepublic
Question
April 11, 2013 at 01:10 PM
glenn

Word 2013 – previous macro building table not working

by glenn . Updated 13 years, 2 months ago

I wrote a forms macro in Word 2000 that reads a text file in a specific directory and determines what form to make based on the text, such as an invoice form, a purchase order form, etc. The macro starts by setting the margins and using a table to build the form. Each version of Word since 2000 has works until Word 2013. The table gets scrambled as part of the build process and everything gets pushed to the left with some of the table columns completely off the page.

My margin macro codes is the following…
DOCNAME1.PageSetup.LeftMargin = 40
DOCNAME1.PageSetup.RightMargin = 40
DOCNAME1.PageSetup.TopMargin = 40
DOCNAME1.PageSetup.BottomMargin = 40
where I am using DOCNAME1 to identify the current active document, for some specific reasons with the forms and other potential documents open at the same time.

Then I insert tables and change the formating…
DOCNAME1.Tables.Add Range:=Selection.Range, NumRows:=1, NumColumns:=1
DOCNAME1.Tables(1).AutoFitBehavior wdAutoFitFixed
Selection.Tables(1).PreferredWidthType = wdPreferredWidthPoints
Selection.Tables(1).PreferredWidth = InchesToPoints(7.55)

DOCNAME1.Tables(1).Select
Selection.Cells.Split 1, 3, 2
Selection.Borders(wdBorderTop).LineStyle = wdLineStyleNone
Selection.Borders(wdBorderLeft).LineStyle = wdLineStyleNone
Selection.Borders(wdBorderBottom).LineStyle = wdLineStyleNone
Selection.Borders(wdBorderRight).LineStyle = wdLineStyleNone
Selection.Borders(wdBorderVertical).LineStyle = wdLineStyleNone
‘Selection.MoveRight Unit:=wdCell, Count:=1
‘Selection.SelectColumn
With ActiveDocument.Tables(1)
.Columns(1).Width = InchesToPoints(2.1)
.Columns(2).Width = InchesToPoints(3.2)
.Columns(3).Width = InchesToPoints(2.25)
End With
By the time it gets this far in Word 2013, the tables are already hosed up in comparison to previous versions.

Any ideas on why Word 2013 is scrambling my tables?

Glenn

This discussion is locked

All Comments