Results 1 to 2 of 2
  1. #1
    3 Star Lounger
    Join Date
    Aug 2002
    Location
    Leuven, Vlaanderen, Belgium
    Posts
    322
    Thanks
    9
    Thanked 0 Times in 0 Posts

    Post 127993 =>OK Re: Can't add field to table cell

    FYI...

    Problem (1) & (2) was solved by inserting the line

    tmpRange.Move Unit:=wdCharacter, Count:=-1

    before each ...Fields.Add ... line!
    Thanks (& find more info there) to <img src=/S/clapping.gif border=0 alt=clapping width=19 height=23> StuartR & his <img src=/S/bananas.gif border=0 alt=bananas width=33 height=35> post 127993, hidden (or didn't I search good enough?) at the end of some other thread...

    Problem (3) was a tough one as it was hard to make texts & fields appear in the right order (something wrong with me defining ranges... but maybe with Word too, as it was pretty weird). For those interested: this is the result... Please leave some comment if you find it crap <img src=/S/bummer.gif border=0 alt=bummer width=15 height=15>/worth the effort <img src=/S/clever.gif border=0 alt=clever width=15 height=15>!
    ================
    Public Sub testsub()

    Dim myRange, tmpRange As Range

    'Insert table in footer
    Set myRange = ActiveDocument.Sections(1).Footers(wdHeaderFooterP rimary).Range
    myRange.Delete
    Set tmpRange = myRange
    myRange.Tables.Add tmpRange, 1, 3

    'Make table borders invisible
    myRange.Tables(1).Borders.OutsideLineStyle = wdLineStyleNone

    'Insert file name field in column 1
    Set tmpRange = myRange.Tables(1).Columns(1).Cells(1).Range '.Duplicate
    tmpRange.Move Unit:=wdCharacter, Count:=-1
    tmpRange.Fields.Add tmpRange, wdFieldFileName

    'Insert fields & text "Pg.x/y" in column 2
    Set tmpRange = myRange.Tables(1).Columns(2).Cells(1).Range '.Duplicate
    tmpRange.Move Unit:=wdCharacter, Count:=-1
    tmpRange.Fields.Add tmpRange, wdFieldSectionPages
    tmpRange.InsertBefore "/"
    tmpRange.SetRange myRange.Tables(1).Columns(2).Cells(1).Range.Start, myRange.Tables(1).Columns(2).Cells(1).Range.Start
    tmpRange.Fields.Add tmpRange, wdFieldPage
    tmpRange.InsertBefore "Pg."

    'Insert date last saved field in column 3
    Set tmpRange = myRange.Tables(1).Columns(3).Cells(1).Range
    tmpRange.Move Unit:=wdCharacter, Count:=-1
    tmpRange.Fields.Add tmpRange, wdFieldEmpty, "SAVEDATE @ ""dd/MM/yy""", PreserveFormatting:=True

    'Update fields
    ActiveDocument.Fields.Update

    End Sub

  2. #2
    3 Star Lounger
    Join Date
    Aug 2002
    Location
    Leuven, Vlaanderen, Belgium
    Posts
    322
    Thanks
    9
    Thanked 0 Times in 0 Posts

    Can't add field to table cell (Word 97)

    I'm writing a Word macro/procedure to add a three-columns-one-row table to the document's footer containing filename (left), page x/y (middle) & date saved (right). I get a run time error message indicating that the fields.add method is not available.

    Can anyone tell me
    (1) what I'm doing wrong for having no access to the fields.add method in the footer table cell?
    => I assume there must be some incompatibility between the table cell as a range and the fields.add method.
    Why? Everything works when adding the field in the 'body' of the document (so fields.add works), when adding it without a table in the footer of the document (so footer range seems to be no obstacle either) or when adding text to footer table cells using e.g. tmpRange.text = "text", and tmpRange.insertafter = "text" methods (so adding text to table cells works too).
    (2) a better way to get the result?
    => I could avoid the table and use one centered paragraph in which I insert something like left field - tabtabtab - middle fields & text - tabtabtab - right field, measuring a bit untill it always +- fits on one line. This might work if the field name length doesn't vary (too) much (the other fields lengths remain stable). But that seems such a hassle fi there's an alternative...
    (3) optional: how to add the mixture of text & fields for 'page X/Y' in the middle column... (I got all mixed up with how to properly use ranges & range methods here.)

    Any help is greatly appreciated. I lost already more hours than I can afford, so I'm ready for giving up the fight... but it's too much a pity, being (probably) so close.
    So... thanks in advance!

    Hans

    P.S. My purpose: I want to standardise (+- uniform layout) 2000 word documents for delivery to our partners. I use an Access file which executes a Word macro (stored in the normal template) on multiple documents (using a table in which the file paths are previously automatically 'loaded' into). So it works great, if ( <img src=/S/crybaby.gif border=0 alt=crybaby width=15 height=15>) the macro does...
    FYI: I only use the RANGE object as I'll probably hide the Word application to speed up the processing and I've read (!?) that the SELECTION object might not work in these circumstances.

Posting Permissions

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