setting preferred width of table in word ONLY works with breakpoint RRS feed

  • Question

  • I am running Office 2007 in Windows XP Professional.

    I have a Macro, written in Excel VBA, which is used to import data from an excel spreadsheet into a Word document. For one particular table, I want most of the columns to be autofitted to their contents, except that I want the fifth column to be a particular width, so that when printed, it has room for hand-written comments.

    In the following segment of code, myWordDoc is a variable that I set to the word document I am editing earlier in the code, and myTable is a variable that I set to the table I'm editing, at the time when I insert it, and in this case has 7 columns:

    myWordDoc.Sections(6).Range.Font.Name = "Calibri"
    myTable.Range.Font.Size = 8
    myWordDoc.Sections(6).Range.Paragraphs(1).Range.Font.Size = 10
    myTable.Columns(5).PreferredWidthType = 2
    myTable.Columns(5).PreferredWidth = 25

    This segment of code works only if I add a breakpoint on the line that reads

    myTable.Columns(5).PreferredWidth = 25

    If I let it run up to the breakpoint, then just click the run button again and let it finish, it works perfectly. If I do not add a breakpoint, the fifth column retains its autofitted width, which is very narrow, because there is no text in it. Why would this happen?!?! Any thoughts or suggestions are greatly appreciated.



    Friday, April 11, 2014 4:27 PM