Added two fields on the form "x / y" in the top cell in a table oftwo rows in the footer

Discussion in 'Word VBA Beginners' started by pmm, Nov 8, 2010.

  1. pmm

    pmm Guest

    Hi - After many attempts, I have almost given up. Hoping to find help
    in here.

    Should have added two fields on the form "x / y" in the top cell in a
    table of two rows in the footer.
    The code below shows what I could find, but do not operate optimally.
    Can not get the fields inserted in the upper cell, nor have the slash
    between the two fields.

    Sub InsertFields_FooterCell()

    Dim rngCell As Range
    Set rngCell =
    ActiveDocument.Sections(1).Footers(wdHeaderFooterPrimary).Range.Tables(1).Cell(1,
    1).Range

    rngCell.Collapse wdCollapseEnd

    Set rngCell = rngCell.Paragraphs(1).Range
    With rngCell
    .Collapse wdCollapseEnd
    .Fields.Add Range:=rngCell, Type:=wdFieldNumPages
    .Collapse wdCollapseEnd
    .Text = "/"
    .Collapse wdCollapseEnd
    .Fields.Add Range:=rngCell, Type:=wdFieldPage
    End With

    Set rngCell = rngCell.Paragraphs(1).Range
    rngCell.Fields.Update

    End Sub
     
    pmm, Nov 8, 2010
    #1
    1. Advertisements

  2. pmm

    Munim Rashid Guest

    Re: Added two fields on the form "x / y" in the top cell in a tableoftwo rows in the footer

    My friend, I too was frustrated like you and just found a solution :) Code here self-explanatory and simple, so I am not describing unless you ask for.

    Set objSelection = objWord.Selection

    With ActiveDocument.Sections(1)
    .Headers(wdHeaderFooterPrimary).Range.text = "My Report"
    .Footers(wdHeaderFooterPrimary).Range.Select
    Selection.TypeText "Page: "
    Selection.Fields.ADD Selection.Range, wdFieldPage
    Selection.Paragraphs.Alignment = wdAlignParagraphRight
    Selection.TypeText "/"
    Selection.Fields.ADD Selection.Range, wdFieldNumPages
    End With

    objSelection.Select


    > On Monday, November 08, 2010 3:57 PM pmm wrote:


    > Hi - After many attempts, I have almost given up. Hoping to find help
    > in here.
    >
    > Should have added two fields on the form "x / y" in the top cell in a
    > table of two rows in the footer.
    > The code below shows what I could find, but do not operate optimally.
    > Can not get the fields inserted in the upper cell, nor have the slash
    > between the two fields.
    >
    > Sub InsertFields_FooterCell()
    >
    > Dim rngCell As Range
    > Set rngCell =
    > ActiveDocument.Sections(1).Footers(wdHeaderFooterPrimary).Range.Tables(1).Cell(1,
    > 1).Range
    >
    > rngCell.Collapse wdCollapseEnd
    >
    > Set rngCell = rngCell.Paragraphs(1).Range
    > With rngCell
    > .Collapse wdCollapseEnd
    > .Fields.Add Range:=rngCell, Type:=wdFieldNumPages
    > .Collapse wdCollapseEnd
    > .Text = "/"
    > .Collapse wdCollapseEnd
    > .Fields.Add Range:=rngCell, Type:=wdFieldPage
    > End With
    >
    > Set rngCell = rngCell.Paragraphs(1).Range
    > rngCell.Fields.Update
    >
    > End Sub
     
    Munim Rashid, Apr 15, 2011
    #2
    1. Advertisements

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.
Similar Threads
  1. Steve

    Deleting table rows in a protected document

    Steve, Nov 14, 2003, in forum: Word VBA Beginners
    Replies:
    1
    Views:
    140
    Doug Robbins - Word MVP
    Nov 14, 2003
  2. Örjan Skoglösa

    insert pagenumber in table in footer

    Örjan Skoglösa, Apr 6, 2004, in forum: Word VBA Beginners
    Replies:
    1
    Views:
    189
    Örjan Skoglösa
    Apr 6, 2004
  3. Carlos Chalhoub

    Space added to variable

    Carlos Chalhoub, May 20, 2004, in forum: Word VBA Beginners
    Replies:
    2
    Views:
    132
    Carlos Chalhoub
    May 20, 2004
  4. alfonso gonzales

    to replace Bold/Underlined text with itself and added something

    alfonso gonzales, Sep 26, 2004, in forum: Word VBA Beginners
    Replies:
    5
    Views:
    108
    alfonso gonzales
    Sep 29, 2004
  5. Jing You

    How to Update Fields in Shapes or Header or Footer?

    Jing You, Sep 30, 2004, in forum: Word VBA Beginners
    Replies:
    1
    Views:
    272
    Jean-Guy Marcil
    Sep 30, 2004
  6. Jesper Fjølner

    Inserting table at bookmark instead of top of document

    Jesper Fjølner, Mar 4, 2005, in forum: Word VBA Beginners
    Replies:
    2
    Views:
    93
    Jesper Fjølner
    Mar 7, 2005
  7. Saveset
    Replies:
    1
    Views:
    229
    Saveset
    May 12, 2010
  8. bts
    Replies:
    1
    Views:
    410
    Doug Robbins - Word MVP
    Jun 23, 2010
Loading...