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

    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
     
    Munim Rashid, Apr 15, 2011
    #2
    1. Advertisements

Ask a Question

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.