Re: Insert text - Footer - all Sections by Kerri
Kerri
Wed Mar 14 14:57:15 CDT 2007
Thank you Jezebel! I'll get the hang of this eventually...without the
help of people like you, I would have given up on VBA a long time
ago. I've learned so much, thanks.
I agree the document property would be much easier to work with,
unfortunately I use a "Document Management" program. Where you have
to profile the document with specific information. So I have to
pragmatically go in and get the specific data like document number,
Client/Matter Number, Author & Typist of Doc and date. So I might be
posting again if I run in to more problems.
Thank you again!
Kerri
On Mar 13, 7:24 pm, "Jezebel" <warcri...@whitehouse.gov> wrote:
> The Selection object is just a special kind of Range object. A Range is any
> continuous part of the document, defined by a start and end point. Nothing
> more. All the things you are currently doing with the Selection, you can do
> (better) with the relevant Range object instead.
>
> 1. The 'lines' in your footer are paragraphs (same as in the body of the
> document), so this step is unnecessary: just use InsertAfter to add your new
> stuff to the end of the existing footer. If it's empty it creates the
> content; if it's not empty it appends it.
>
> 2. --
>
> With pFooter.Find
> .Text = "^#^#^#^#^#^#^#.^#"
> If .execute then
> ...
> end if
> End with
>
> etc
>
> However, there are better ways to put numbers into your footers. Simpler is
> to use a DocProperty field, then set the number as a document property.
>
> "Kerri" <jkbourl...@att.net> wrote in message
>
> news:1173836947.989941.34950@b75g2000hsg.googlegroups.com...
>
>
>
> > Hi Jezebel,
>
> > Okay, I added wdPrimaryFooterSory and to the code and it added the
> > text in the rest of the sections.
>
> > I do have another question though.
>
> > My goal is to do each of the following listed below to each section.
> > How do us the pFooter story range to accomplish it. Before I would
> > open the footer and use selection and range to accomplish my tasks.
> > Is this still possible?
>
> > 1. Check to see if there is data in the footer, if so then go to the
> > end of the line and create a new line. If not, go to the beginning of
> > the current line.
> > 2. If a document number exists(I do a find for ^#^#^#^#^#^#^#.^#)
> > then select it and go to #3, If number does not exist then add hard
> > return and go to #3.
> > 3. Create a bookmark at the new selection and insert code into that
> > bookmark
>
> > Sub FooterText()
> > Dim pFooter As Word.Range
> > Dim pIndex As Long
> > For pIndex = 1 To 4
> > On Error Resume Next
> > Set pFooter = ActiveDocument.StoryRanges(Choose(pIndex,
> > wdEvenPagesFooterStory, wdFootnotesStory, wdPrimaryFooterStory,
> > wdFirstPageFooterStory))
> > On Error GoTo 0
> > Do Until pFooter Is Nothing
> > :
> > ' pFooter.Text = "blah blah blah"
> > pFooter.InsertAfter "Addition text"
> > :
> > Set pFooter = pFooter.NextStoryRange
> > Loop
> > Next
> > End Sub
>
> > On Mar 12, 7:08 pm, "Jezebel" <warcri...@whitehouse.gov> wrote:
> >> You need to modify this bit of code to read the existing content and
> >> replacing it with the text you want --
>
> >> pFooter.Text = "blah blah blah"
>
> >> eg,
>
> >> pFooter.InsertAfter "Addition text"
>
> >> "Kerri" <jkbourl...@att.net> wrote in message
>
> >>news:1173739988.001819.17510@p10g2000cwp.googlegroups.com...
>
> >> > Hi Jezebel,
> >> > Thank you for taking the time to respond, I appreciate your help.
>
> >> > The only place it is putting the text is in the First page footer and
> >> > it deletes all the exisiting text. I need to keep the text and be
> >> > able to insert the text at a specific location or at the end of any
> >> > existing text. The document I tested it on had Four pages with three
> >> > sections all with link to previous turned off and only the first
> >> > section had diff. first page with a second page for a total of 4
> >> > pages.
>
> >> > What did I do wrong?
>
> >> > On Mar 12, 3:11 pm, "Jezebel" <warcri...@whitehouse.gov> wrote:
> >> >> Dim pFooter as word.range
> >> >> Dim pIndex as long
>
> >> >> For pIndex = 1 to 3
> >> >> on error resume next
> >> >> set pFooter = ActiveDocument.StoryRanges(Choose(pIndex,
> >> >> wdEvenPagesFooterStory, wdFirstPageFooterStory, wdFootnotesStory))
> >> >> on error goto 0
>
> >> >> Do until pFooter is nothing
> >> >> :
> >> >> pFooter.Text = "blah blah blah"
> >> >> :
> >> >> set pFooter = pFooter.NextStoryRange
> >> >> Loop
> >> >> Next
>
> >> >> "Kerri" <jkbourl...@att.net> wrote in message
>
> >> >>news:1173734392.593230.158840@j27g2000cwj.googlegroups.com...
>
> >> >> > Hi,
>
> >> >> > I'm in Word 2003, I am trying to insert text in to all sections
> >> >> > including first page header. I don't want to just remove what is
> >> >> > already there. I need to see if a doc number appears if so then
> >> >> > delete just that. I have the guts figured out. My problem it's not
> >> >> > moving to the next header if it exists and it's inserting my text
> >> >> > three times in the first page. I got this code from another help
> >> >> > file. The code below has been modified and is my trimed down
> >> >> > version.
> >> >> > Any help would be greatly appreciated.
>
> >> >> > Sub HDFtrSections()
> >> >> > Dim i As Long
> >> >> > Dim ftr As HeaderFooter
> >> >> > Dim sec As Section
> >> >> > Dim rng As Range
>
> >> >> > WordBasic.ViewFooter 'I know I should update this but it still
> >> >> > works.
>
> >> >> > With ActiveDocument
> >> >> > For i = 1 To .Sections.Count
> >> >> > 'loop through each section in doc
> >> >> > For Each ftr In .Sections(i).Footers
>
> >> >> > 'Don't remove existing text
> >> >> > 'Don't add a hard return if the range is ""
> >> >> > 'If bkmk exists then delete text
> >> >> > 'if Find.found = True then delete text
> >> >> > 'Create new bookmark and insert doc name.
>
> >> >> > Selection.Range.Text = "blah blah blah"
>
> >> >> > 'It stays in the same footer repeating the steps.
> >> >> > 'The first footer is First Page footer.
> >> >> > 'Or it inserts the text three times. For the number of
> >> >> > sections.
> >> >> > Next ftr
> >> >> > Next i
> >> >> > End With
> >> >> > End Sub
>
> >> >> > Thank you for your time.
> >> >> > Kerri- Hide quoted text -
>
> >> >> - Show quoted text -- Hide quoted text -
>
> >> - Show quoted text -- Hide quoted text -
>
> - Show quoted text -