Prev: Delete rows from a table
Next: MsgBox with number of paragraphs formatted with a user-defined paragraph style
From: Ian B on 3 May 2010 00:24 Hi I wrote a routine many years ago which has worked fine. I now have to insert another string in the footer using a different font size. I've experimented for hours but my footer always ends up with all footer text at 16 pts. The documents are very large with up to 30 sections so to actually manipulate the footers by opening them and inserting required text is unacceptably slow.. See my attempts below: I think I need to introduce a selection into the footer, but the footers(xx) works only with a range and that range seems to be the whole footer. I think I'm "dead in the water", but any help much appreciated. Cheers Ian B ~~~~~~~~~~~~~~ With ActiveDocument.Sections(lS).Footers(wdHeaderFooterFirstPage).Range .Paragraphs.TabStops.ClearAll .Font.Size = 8 .ParagraphFormat.TabStops.Add Position:=CentimetersToPoints(17), Alignment:=wdAlignTabRight, Leader:=wdTabLeaderSpaces .InsertAfter Text:=sPath & vbTab & "_________Initials" & vbCrLf End With With ActiveDocument.Sections(lS).Footers(wdHeaderFooterPrimary).Range .Font.Size = 16 Selection.InsertAfter Text:=sInsertString End With
From: Ian B on 3 May 2010 00:51 Sorry, my cut & paste was not that great, the second "with" should be "wdHeaderFooterFirstPage" "Ian B" <ian@(TakeOut)docspro.co.nz> wrote in message news:uKC99hn6KHA.3536(a)TK2MSFTNGP04.phx.gbl... > Hi > I wrote a routine many years ago which has worked fine. > I now have to insert another string in the footer using a different font > size. > I've experimented for hours but my footer always ends up with all footer > text at 16 pts. > The documents are very large with up to 30 sections so to actually > manipulate the footers by opening them and inserting required text is > unacceptably slow.. > See my attempts below: > I think I need to introduce a selection into the footer, but the > footers(xx) works only with a range and that range seems to be the whole > footer. > > I think I'm "dead in the water", but any help much appreciated. > > Cheers > > Ian B > ~~~~~~~~~~~~~~ > With ActiveDocument.Sections(lS).Footers(wdHeaderFooterFirstPage).Range > .Paragraphs.TabStops.ClearAll > .Font.Size = 8 > .ParagraphFormat.TabStops.Add Position:=CentimetersToPoints(17), > Alignment:=wdAlignTabRight, Leader:=wdTabLeaderSpaces > .InsertAfter Text:=sPath & vbTab & "_________Initials" & vbCrLf > End With > > With ActiveDocument.Sections(lS).Footers(wdHeaderFooterPrimary).Range > .Font.Size = 16 > Selection.InsertAfter Text:=sInsertString > End With > > > >
From: Graham Mayor on 3 May 2010 00:55 It is simply a matter of setting the ranges accurately to reflect what you want to do e.g. to add some 16 point text to an existing First Page header in Section 1 without changing the content of the header Dim oHeader As HeaderFooter Dim oRng As Range Set oHeader = ActiveDocument.Sections(1) _ ..Headers(wdHeaderFooterFirstPage) Set oRng = oHeader.Range With oRng .InsertAfter vbCr .Start = oHeader.Range.End .Text = "This is the additional text" .End = oHeader.Range.End .Font.Size = 16 .Fields.Update End With To add the text after all headers Dim oSection As Section Dim oHeader As HeaderFooter Dim oRng As Range For Each oSection In ActiveDocument.Sections For Each oHeader In oSection.Headers Set oRng = oHeader.Range With oRng If Len(oRng) > 1 Then .InsertAfter vbCr End If .Start = oHeader.Range.End .Text = "This is the additional text" .End = oHeader.Range.End .Font.Size = 16 .Fields.Update End With Next oHeader Next oSection -- <>>< ><<> ><<> <>>< ><<> <>>< <>><<> Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org <>>< ><<> ><<> <>>< ><<> <>>< <>><<> "Ian B" <ian@(TakeOut)docspro.co.nz> wrote in message news:uKC99hn6KHA.3536(a)TK2MSFTNGP04.phx.gbl... > Hi > I wrote a routine many years ago which has worked fine. > I now have to insert another string in the footer using a different font > size. > I've experimented for hours but my footer always ends up with all footer > text at 16 pts. > The documents are very large with up to 30 sections so to actually > manipulate the footers by opening them and inserting required text is > unacceptably slow.. > See my attempts below: > I think I need to introduce a selection into the footer, but the > footers(xx) works only with a range and that range seems to be the whole > footer. > > I think I'm "dead in the water", but any help much appreciated. > > Cheers > > Ian B > ~~~~~~~~~~~~~~ > With ActiveDocument.Sections(lS).Footers(wdHeaderFooterFirstPage).Range > .Paragraphs.TabStops.ClearAll > .Font.Size = 8 > .ParagraphFormat.TabStops.Add Position:=CentimetersToPoints(17), > Alignment:=wdAlignTabRight, Leader:=wdTabLeaderSpaces > .InsertAfter Text:=sPath & vbTab & "_________Initials" & vbCrLf > End With > > With ActiveDocument.Sections(lS).Footers(wdHeaderFooterPrimary).Range > .Font.Size = 16 > Selection.InsertAfter Text:=sInsertString > End With > > >
From: Fumei2 via OfficeKB.com on 3 May 2010 14:13 OR..... If you use Styles fully; Sub AddText2Footer() With ActiveDocument.Sections(1).Footers(wdHeaderFooterPrimary) .Range.Text = .Range.Text & "Additional text." .Range.Paragraphs(.Range.Paragraphs.Count).Style = "AdditionalFooter" End With End Sub This takes the original footer text content (which MUST terminate with a paragraph mark), appends the text "Additional text.", then applies the style "AdditionalText" to the LAST paragraph in the range (i.e. the newly added paragraph). Assuming of course the additional text is indeed being added to the end. If it is not, then yes you have to work within the range. Gerry Graham Mayor wrote: >It is simply a matter of setting the ranges accurately to reflect what you >want to do e.g. to add some 16 point text to an existing First Page header >in Section 1 without changing the content of the header > >Dim oHeader As HeaderFooter >Dim oRng As Range >Set oHeader = ActiveDocument.Sections(1) _ >.Headers(wdHeaderFooterFirstPage) >Set oRng = oHeader.Range >With oRng > .InsertAfter vbCr > .Start = oHeader.Range.End > .Text = "This is the additional text" > .End = oHeader.Range.End > .Font.Size = 16 > .Fields.Update >End With > >To add the text after all headers > >Dim oSection As Section >Dim oHeader As HeaderFooter >Dim oRng As Range >For Each oSection In ActiveDocument.Sections > For Each oHeader In oSection.Headers > Set oRng = oHeader.Range > With oRng > If Len(oRng) > 1 Then > .InsertAfter vbCr > End If > .Start = oHeader.Range.End > .Text = "This is the additional text" > .End = oHeader.Range.End > .Font.Size = 16 > .Fields.Update > End With > Next oHeader >Next oSection > >> Hi >> I wrote a routine many years ago which has worked fine. >[quoted text clipped - 28 lines] >> Selection.InsertAfter Text:=sInsertString >> End With -- Gerry Message posted via http://www.officekb.com
From: Fumei2 via OfficeKB.com on 3 May 2010 14:14 Whooops, I meant: With ActiveDocument.Sections(1).Footers(wdHeaderFooterFirstPage) Gerry Fumei2 wrote: >OR..... > >If you use Styles fully; > >Sub AddText2Footer() >With ActiveDocument.Sections(1).Footers(wdHeaderFooterPrimary) > .Range.Text = .Range.Text & "Additional text." > .Range.Paragraphs(.Range.Paragraphs.Count).Style = "AdditionalFooter" >End With >End Sub > >This takes the original footer text content (which MUST terminate with a >paragraph mark), appends the text "Additional text.", then applies the style >"AdditionalText" to the LAST paragraph in the range (i.e. the newly added >paragraph). > >Assuming of course the additional text is indeed being added to the end. If >it is not, then yes you have to work within the range. > >Gerry >>It is simply a matter of setting the ranges accurately to reflect what you >>want to do e.g. to add some 16 point text to an existing First Page header >[quoted text clipped - 40 lines] >>> Selection.InsertAfter Text:=sInsertString >>> End With > -- Gerry Message posted via OfficeKB.com http://www.officekb.com/Uwe/Forums.aspx/word-programming/201005/1
|
Next
|
Last
Pages: 1 2 Prev: Delete rows from a table Next: MsgBox with number of paragraphs formatted with a user-defined paragraph style |