Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 01-10-2017, 06:52 AM
jmltinc jmltinc is offline 3 Column x of y Footer Windows 7 64bit 3 Column x of y Footer Office 2016
Novice
3 Column x of y Footer
 
Join Date: Jan 2017
Posts: 9
jmltinc is on a distinguished road
Default 3 Column x of y Footer

Hi Folks,



I am having a time with this and have not been able to obtain a solution. I am fluent in VBA (Access), but Word is another animal...

From LabVIEW, I am opening an instance of Word, inserting a VBA module, and calling that module. From Word, the module then formats the document, populates it with test data passed by LabVIEW, prints it as a report for the customer, and closes the Word instance. The report must be created by VBA (no Macro) and insert a Footer on each page. The Footer requires three columns with the center column showing 'Page x of y' to look like:
QMF 24 Rev D ---------- Page 1 of 2---------- PRM 05/ Section 4.6

I tried inserting a 3 column table inside the Footer using code I found:

Code:
    Set myrange = _
ActiveDocument.Sections(1).Footers(wdHeaderFooterPrimary).Range
    Set mytable = _
ActiveDocument.Tables.Add(ActiveDocument.Sections(1).Footers(wdHeaderFooterPrimary).Range, 1, 3)
    With mytable
        .Cell(1, 1).Range.Text = "QMF 24 Rev D"
        .Cell(1, 1).Range.Paragraphs(1).Alignment = wdAlignParagraphCenter
    End With
    Set myrange = mytable.Cell(1, 2).Range
    myrange.End = myrange.End - 1
    myrange.Collapse wdCollapseEnd
    mytable.Cell(1, 2).Select
    With Selection
        .Paragraphs(1).Alignment = wdAlignParagraphCenter
        .TypeText Text:="Page "
        .Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, Text:="PAGE ", PreserveFormatting:=True
        .TypeText Text:=" of "
        .Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, Text:="NUMPAGES ", PreserveFormatting:=True
    End With
    With mytable
        .Cell(1, 3).Range.Text = "PRM 05/Section 4.6"
        .Cell(1, 3).Range.Paragraphs(1).Alignment = wdAlignParagraphCenter
    End With
But, this code does not show the current page number (Page 1 of y shows y of y). I am presuming PAGE and NUMPAGES are reserved words and return the page numbers, but are meant for Macros???? In any event, I am lost as to how the numbering takes place.

I tried this code I found (without table):

Code:
    With .Footers(wdHeaderFooterPrimary)
        Set rng = .Range.Duplicate
        rng.Text = "QMF 24 Rev D"
        rng.Collapse wdCollapseEnd
        rng.InsertBefore vbTab & "Page  of "
        rng.Collapse wdCollapseStart
        rng.Move wdCharacter, 6
        ThisDocument.Fields.Add rng, wdFieldPage
        Set rng = .Range.Duplicate
        rng.Collapse wdCollapseEnd
        ThisDocument.Fields.Add rng, wdFieldNumPages
        rng.Collapse wdCollapseEnd
     End With
It works very well, but I have no idea how to insert the third column text and right-justify so all text are evenly spaced. Further, this code is even more a mystery to me. I do not understand the concept of the Collapse method. My research tells me it has no effect on the document unless it is applied to an object using the SET keyword. Then there is the Duplicate Method...

1) Can anyone help me make either code snippet work as I need it?
2) Microsoft's online Help is so very vague explaining their Objects, Properties, and Methods. Can I be enlightened about Word's Object model regarding this, please?

Thanks,
-John

Last edited by macropod; 01-10-2017 at 11:55 AM. Reason: Added code tags
Reply With Quote
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
Header and footer aligned in the footer area ashiqghfr Word 2 07-23-2015 01:14 AM
3 Column x of y Footer documents saved with double column revert to single column when re-opened danw Word 6 04-08-2015 06:24 AM
How can I temporarily break a 3 column format in order to type a single column paragraph William P Word 1 01-04-2015 06:40 PM
Footer - more then one footer (auto fill text in slides) noodle PowerPoint 0 03-31-2013 04:50 AM
Two column format without affecting neither the page numbers nor the header or footer Jamal NUMAN Word 4 02-21-2012 03:20 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 01:44 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft