Results 1 to 3 of 3
  1. #1
    Lounger
    Join Date
    Nov 2003
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    26
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Force Word to Complete Column Adjust (English/Word/2007)

    I have a word macro that performs a number of functions, the final bit, at this stage, is to adjust a column width in a table and then to display the number of pages. Unfortunately it does not actually adjust the column width until after the number of pages is shown, so the number shown is wrong. I've tried many things to force this update including moving the selection focus away from the table and inserting a paragraph at the end, moving to the beginning and end of the document and performing an activedocument.repaginate command. Nothing works. The code displays the number of pages and waits for the user to click OK and then adjusts the column width and repaginates. Anyone have any idea how to make word complete its changes before displaying the number of pages? I've shown a snippet of the code below.

    '.... much code before this - at this point we are working within a table at the end of the document
    Selection.Columns.PreferredWidth = CentimetersToPoints(1)
    Selection.ParagraphFormat.Alignment = wdAlignParagraphRight
    Selection.Tables(1).Rows.Alignment = wdAlignRowCenter

    'this is just my latest attempt to force word to update the document
    Selection.EndKey Unit:=wdStory
    ActiveDocument.Repaginate

    'User function to show status - we are unloading a modeless form at this stage
    ShowStatus "UNLOADFORM"

    'Simply re-establishing the active window - the modeless form unload changed the active window status
    Windows(1).Activate

    total_pages = Selection.Information(wdNumberOfPagesInDocument)
    response = MsgBox(Str(total_pages))

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

    Re: Force Word to Complete Column Adjust (English/Word/2007)

    Do you have

    Application.ScreenUpdating = False

    somewhere in your code before this point? If so, include

    Application.ScreenUpdating = True

    You can also try replacing PreferredWidth with Width.

  3. #3
    Lounger
    Join Date
    Nov 2003
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    26
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Force Word to Complete Column Adjust (English/Word/2007)

    Thanks Hans. The use of Width instead of PreferredWidth worked. Seems that with PreferredWidth, the table never gets updated until the macro is finished. I've been tearing my hair out, trying all sorts of things and never even noticed this one, so thanks heaps.

Posting Permissions

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