none
VB.net Word Automation (Footer Page Numbers) RRS feed

  • Question

  • Hi, I am trying to insert some text AND page numbers within a word document I am creating, I can create one or the other but not both at the same time - is this possible?:

            With wrdDataDoc.Sections(1).Footers(Word.WdHeaderFooterIndex.wdHeaderFooterPrimary).Range
                .Fields.Add(wrdDataDoc.Sections(1).Footers(WdHeaderFooterIndex.wdHeaderFooterPrimary).Range, WdFieldType.wdFieldPage)
                .ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphCenter
            End With
    
    
            With wrdDataDoc.Sections(1).Footers(Word.WdHeaderFooterIndex.wdHeaderFooterPrimary).Range
                .Text = "Company Name plc"
                .InlineShapes.AddHorizontalLineStandard()
                .ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphLeft
            End With

    Wednesday, March 26, 2014 11:20 AM

Answers

  • Try something along the lines of:

    With wrdDataDoc
      .Fields.Add(.Sections(1).Footers(WdHeaderFooterIndex.wdHeaderFooterPrimary).Range, WdFieldType.wdFieldPage)
      With .Sections(1).Footers(WdHeaderFooterIndex.wdHeaderFooterPrimary).Range
        .ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphCenter
        .Characters.Last.InsertParagraphAfter
        With .Paragraphs.Last.Range
          .InsertAfter "Company Name plc"
          .InlineShapes.AddHorizontalLineStandard()
          .ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphLeft
        End With
      End With
    End With

    Note: I don't do VB.Net, so the above might not be quite right. A working VBA equivalent is:

    With ActiveDocument
      .Fields.Add .Sections(1).Footers(wdHeaderFooterPrimary).Range, wdFieldPage
      With .Sections(1).Footers(wdHeaderFooterPrimary).Range
        .ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphCenter
        .Characters.Last.InsertParagraphAfter
        With .Paragraphs.Last.Range
          .InsertAfter "Company Name plc"
          .InlineShapes.AddHorizontalLineStandard
          .ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphLeft
        End With
      End With
    End With


    Cheers
    Paul Edstein
    [MS MVP - Word]

    Thursday, March 27, 2014 1:48 AM

All replies

  • Hi,

    I'm afraid that it is not the correct forum about this issue, since this forum is to discuss Visual Basic.

    So I have moved this thread to Word for Developers forum for better response.

    Thanks for your understanding.

    Best regards,
    Franklin


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Thursday, March 27, 2014 1:15 AM
  • Try something along the lines of:

    With wrdDataDoc
      .Fields.Add(.Sections(1).Footers(WdHeaderFooterIndex.wdHeaderFooterPrimary).Range, WdFieldType.wdFieldPage)
      With .Sections(1).Footers(WdHeaderFooterIndex.wdHeaderFooterPrimary).Range
        .ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphCenter
        .Characters.Last.InsertParagraphAfter
        With .Paragraphs.Last.Range
          .InsertAfter "Company Name plc"
          .InlineShapes.AddHorizontalLineStandard()
          .ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphLeft
        End With
      End With
    End With

    Note: I don't do VB.Net, so the above might not be quite right. A working VBA equivalent is:

    With ActiveDocument
      .Fields.Add .Sections(1).Footers(wdHeaderFooterPrimary).Range, wdFieldPage
      With .Sections(1).Footers(wdHeaderFooterPrimary).Range
        .ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphCenter
        .Characters.Last.InsertParagraphAfter
        With .Paragraphs.Last.Range
          .InsertAfter "Company Name plc"
          .InlineShapes.AddHorizontalLineStandard
          .ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphLeft
        End With
      End With
    End With


    Cheers
    Paul Edstein
    [MS MVP - Word]

    Thursday, March 27, 2014 1:48 AM