Re: Writing neat VBA by Doug
Doug
Wed Aug 17 14:33:40 CDT 2005
Not here, also on 2003.
--
Hope this helps.
Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.
Doug Robbins - Word MVP
"Jezebel" <warcrimes@whitehouse.gov> wrote in message
news:uUsq0vwoFHA.3312@tk2msftngp13.phx.gbl...
> Runs fine on my machine (W2003).
>
>
>
> "Doug Robbins" <dkr@REMOVEmvps.org> wrote in message
> news:OFp9y8voFHA.2916@TK2MSFTNGP14.phx.gbl...
>> Neat, but not quite. While it compiles OK without the periods before
>> Footers and Headers, it produces an error when run.
>>
>> This works:
>>
>> Dim pHeaderFooter As Word.HeaderFooter
>> With Selection.Sections(1)
>> For Each pHeaderFooter In .Footers
>> pHeaderFooter.LinkToPrevious = False
>> Next
>> For Each pHeaderFooter In .Headers
>> pHeaderFooter.LinkToPrevious = False
>> Next
>> End With
>>
>>
>> --
>> Hope this helps.
>>
>> Please reply to the newsgroup unless you wish to avail yourself of my
>> services on a paid consulting basis.
>>
>> Doug Robbins - Word MVP
>> "Jezebel" <warcrimes@whitehouse.gov> wrote in message
>> news:uMxSxZvoFHA.3996@TK2MSFTNGP12.phx.gbl...
>>> If you want to avoid any assumptions about which headers and footers are
>>> defined --
>>>
>>> Dim pHeaderFooter as Word.HeaderFooter
>>> With Selection.Sections(1)
>>> For each pHeaderFooter in Footers
>>> pHeaderFooter.LinkToPrevious = FALSE
>>> Next
>>> For each pHeaderFooter in Headers
>>> pHeaderFooter.LinkToPrevious = FALSE
>>> Next
>>> End With
>>>
>>>
>>>
>>>
>>> "Doug Robbins" <dkr@REMOVEmvps.org> wrote in message
>>> news:utK4zRqoFHA.1412@TK2MSFTNGP09.phx.gbl...
>>>> This is the way to do it:
>>>>
>>>> With Selection.Sections(1)
>>>> .Footers(wdHeaderFooterFirstPage).LinkToPrevious = False
>>>> .Footers(wdHeaderFooterPrimary).LinkToPrevious = False
>>>> .Footers(wdHeaderFooterEvenPages).LinkToPrevious = False
>>>> .Footers(wdHeaderFooterEvenPages).LinkToPrevious = False
>>>> .Headers(wdHeaderFooterFirstPage).LinkToPrevious = False
>>>> .Headers(wdHeaderFooterPrimary).LinkToPrevious = False
>>>> .Headers(wdHeaderFooterEvenPages).LinkToPrevious = False
>>>> .Headers(wdHeaderFooterEvenPages).LinkToPrevious = False
>>>> End With
>>>>
>>>>
>>>> --
>>>> Hope this helps.
>>>>
>>>> Please reply to the newsgroup unless you wish to avail yourself of my
>>>> services on a paid consulting basis.
>>>>
>>>> Doug Robbins - Word MVP
>>>> "Roderick O'Regan" <rory@removethis.theoregans.com> wrote in message
>>>> news:kq84g19gp0tdjpcrtnfklbsau3cpno93ju@4ax.com...
>>>>>I have a document with Odd and Even pages headers and footers.
>>>>>
>>>>> At this point I insert a new section and which I have to remove the
>>>>> header and footer linking to the previous section.
>>>>>
>>>>> I create a temporary bookmark, add a page break, unlink the primary
>>>>> and even headers and footers, remove the bookmark and then the page
>>>>> break.
>>>>>
>>>>> Everything works as it should and there is no problem.
>>>>>
>>>>> However, below is the code which does all the unlinking and I just
>>>>> wanted to say the same thing but with a little more elegance and
>>>>> finesse.
>>>>>
>>>>> Could somebody therefore, please show me how these few lines might be
>>>>> written in properly coded VBA?
>>>>> ======================
>>>>> ActiveWindow.ActivePane.View.SeekView = wdSeekEvenPagesHeader
>>>>> Selection.HeaderFooter.LinkToPrevious = False
>>>>> ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
>>>>> ActiveDocument.Bookmarks("temp").Select
>>>>> ActiveWindow.ActivePane.View.SeekView = wdSeekPrimaryHeader
>>>>> Selection.HeaderFooter.LinkToPrevious = False
>>>>> ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
>>>>> ActiveDocument.Bookmarks("temp").Select
>>>>> ActiveWindow.ActivePane.View.SeekView = wdSeekEvenPagesFooter
>>>>> Selection.HeaderFooter.LinkToPrevious = False
>>>>> ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
>>>>> ActiveDocument.Bookmarks("temp").Select
>>>>> ActiveWindow.ActivePane.View.SeekView = wdSeekPrimaryFooter
>>>>> Selection.HeaderFooter.LinkToPrevious = False
>>>>> ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
>>>>> ========================
>>>>> You might wonder why all the backwards and forwards between the
>>>>> headers, main document and back to the footers with the selection of
>>>>> the temp bookmark in between?
>>>>>
>>>>> Well, I found that Word "got lost"(i.e. didn't go to where I expected
>>>>> it to go) if I told it to unlink the odd and even headers and then do
>>>>> the same with the odd and even footers. It somehow got confused and
>>>>> went and did things either in the previous section or the one
>>>>> following the new section.
>>>>>
>>>>> I created some explicit actions and that did the trick!!
>>>>>
>>>>> Regards
>>>>>
>>>>> Roderick
>>>>
>>>>
>>>
>>>
>>
>>
>
>