Results 1 to 7 of 7
  1. #1
    New Lounger
    Join Date
    Oct 2002
    Posts
    20
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Stepping/Running Code (Word XP)

    I am running table manipulation code, which resizes a table from one size to another depending on the table the user selects. The code uses the Preferred Width option, allowing the table to be sized as selected. In Word 2000 the code when run does not resize the table, but I step through or if I use a breakpoint it does. I placed Application.ScreenRefresh before and after this piece of code and it now works in Word 2000.

    I am using the same piece of code in Word XP and am getting the same problem. The code runs correctly if stepped but if run then the table does not resize. I was hoping that the Application.ScreenRefresh would solve the problem in both 2000 and XP (which is obviously not the case). I've looked at DoEvents and also Wait but nothing seems to work.

    All or any suggestions greatly appreciated.
    Thanks
    Jackie

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Stepping/Running Code (Word XP)

    Would it be possible to post the code, or the relevant part of it? That would enable Loungers to experiment.

  3. #3
    New Lounger
    Join Date
    Oct 2002
    Posts
    20
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Stepping/Running Code (Word XP)

    Hans ..... code as requested. The size of the table is being passed (pdblTableSize), and I've also set the PreferredWith type as points. If I put a breakpoint in at ptblTable.PreferredWidthType - then F5 when it stops, it runs fine, if there is no breakpoint it does not resize.

    Hope this is enough information.
    Thanks
    Jackie

    ' The Screen Refresh is required as the Preferred Width
    code needs time before it is run
    Application.ScreenRefresh
    DoEvents

    #If VBA6 Then
    ptblTable.PreferredWidthType = wdPreferredWidthPoints
    ptblTable.PreferredWidth = pdblTableSize
    Application.ScreenRefresh
    #End If

  4. #4
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Stepping/Running Code (Word XP)

    There are so, so, so many ways for this to go wrong. <img src=/S/grin.gif border=0 alt=grin width=15 height=15> If you have worked at all with tables in FrontPage, and reflect on how Microsoft is trying to cross-breed the properly behaved Word 97 tables with HTML tables, you can understand why I say that.

    If you click in your table, open the VBE (Alt+F11), open the Immediate window (Ctrl+G) and enter the following query and then press Enter at the end of it, what do you get?

    <pre>?selection.Tables(1).PreferredWidth</pre>

    For a table in which I have manually changed ANY of the preferred column widths I get:

    <pre> 9999999 </pre>

    This is the VBA return value for "indeterminate" or "does not compute. Because I caused the sum of the preferred column widths to exceed the preferred table width, the preferred table width is now messed up. The table still IS that width on screen, but it violates the law of physics. If you manually reassign the value of 5 inches (360 points) and try again, you get the same result:

    <pre>selection.Tables(1).PreferredWidth = 360
    ?selection.Tables(1).PreferredWidth

  5. #5
    New Lounger
    Join Date
    Oct 2002
    Posts
    20
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Stepping/Running Code (Word XP)

    I have three tables that are being resized and merged back together (Caption, Data and Source). The code identifies which table then changes the table size accordingly, on the Data table it actually resizes each column so that it is sized proportionately. When using the immediate window I noticed that the Caption and Source tables (one column tables) show the PreferredWidth but the Data table (which has a number of columns) gives 9999999 as it's PreferredWidth.

    Not sure whether this is having an impact on the Resize Table Function when it runs. Also, still am confused why it works in 2000 but not in XP - starting to really dislike the Tables ojbect !!!

    Any ideas would be appreciated.
    Thanks
    Jackie

  6. #6
    Super Moderator
    Join Date
    Dec 2000
    Location
    New York, NY
    Posts
    2,970
    Thanks
    3
    Thanked 29 Times in 27 Posts

    Re: Stepping/Running Code (Word XP)

    Jackie,

    Just as another way around this problem, do you have the option to structure the tables so that the 'Preferred Width' feature is not used in the first place?

    In the user interface, I could never get tables to behave the way I needed them to when the Preferred Width option was set; it just seemed to want to override what I wanted to do with the column widths. Based on that experience, I always avoided using this option when building tables for templates, and when controlling them via code. In my experience it seems much more reliable to avoid using preferred width, and instead to dictate via code, the exact widths you want the columns to be.

    Gary

  7. #7
    New Lounger
    Join Date
    Oct 2002
    Posts
    20
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Stepping/Running Code (Word XP)

    Thanks for the suggestion Gary, unfortunately I'm not able to set the columns, hence I was using the PreferredWidth Option. The user has 5 table options to select, ranging from A4 width table down to a 200 point size table. They also have the ability to increase the columns hence the only thing that I knew for certain was the actual table size they selected.

    What is really frustrating is why this particular code works in Word 2000 but not Word XP - I'm not aware of any differences with tables between the versions? Bl**dy Microsoft !!!!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •