Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #2  
Old 01-10-2017, 10:27 AM
slaycock slaycock is offline 3 Column x of y Footer Windows 7 64bit 3 Column x of y Footer Office 2013
Expert
 
Join Date: Sep 2013
Posts: 255
slaycock is on a distinguished road
Default

Hi John

Your first block of code works fine on my PC.

Code:
Sub test()
Dim myRange As Range
Dim myTable As Table
   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
End Sub
It may be that you need to add

Code:
ActiveDocument.Fields.Update
as the last line to force your fields to update.

The collapse method makes the start and end of the range the same point. If you were to do this on a word you had selected you would see the range contract to just an insertion point. The wdCollapseStart and wdCollapseEnd parameters dictate the direction of the collapse.

So if you had a word selected then the use of wdCollapseStart would move the end of the range to the start of the range and give you an insertion point at the start of the word. Conversely, the use of wdCollapseEnd moves the start of the range to the end of the range and so puts the insertion point at the end of the range.

I'd agree with you that the word help files can be a bit hard to get your head around at times so you have my sympathies there.

I'm not sure but if you want your footer text to be left aligned in Cell(1,1), centered in Cell(1,2) and right aligned in Cell(1,3) then use

wdAlignParagraphLeft
wdAlignParagraphCentered
wdAlignParagraphRight

If you are new to using word then in the VBA IDE goto Tools.Options and make sure that all boxes under 'Code Settings' are ticked.
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 11:21 PM.


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