![]() |
#1
|
|||
|
|||
![]()
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 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 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 |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Header and footer aligned in the footer area | ashiqghfr | Word | 2 | 07-23-2015 01:14 AM |
![]() |
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 |