murphy84
11-07-2007, 02:13 AM
I'm attempting to create a page break to separate the last page from the second to last page in the document. I then need to unlink the previous footer from the blank page section because I want to remove the footer information from the footer details on the blank page but keep the existing footer on the last page.
My VBA code is as follows...
Private Sub SetupDuplexEL()
Dim current_page_no As Integer
Dim current_section_no As Integer
'Goto Bookmark and work out page number
ActiveDocument.Bookmarks("BREAK_ELCERT").Select
current_page_no = Selection.Information(wdActiveEndPageNumber)
'Stop
' Application.Visible = True
'Work out if page is odd or even
If current_page_no Mod 2 = 0 Then
' Its Even
' Goto BREAK_ELCERT_2 and insert page breaks
ActiveDocument.Bookmarks("BREAK_ELCERT_2").Select
'Insert Page Breaks
Selection.InsertBreak Type:=wdSectionBreakNextPage
Selection.InsertBreak Type:=wdSectionBreakNextPage
'Set view to the el footer
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageFooter
'Unlink from previous so old footer doesnt become deleted
Selection.HeaderFooter.LinkToPrevious = False
ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument ' Reset View
'Move up
ActiveDocument.Bookmarks("BREAK_ELCERT_2").Select
Selection.MoveDown Unit:=wdLine, Count:=1
'Goto the header and unlink from previous
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
Selection.HeaderFooter.LinkToPrevious = False
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageFooter
'Select contents in footer and remove it from the blank page
Selection.WholeStory
Selection.Copy
Selection.Delete Unit:=wdCharacter, Count:=1
' ********* Word Hack *********** Footer details get deleted so put back in!
ActiveWindow.ActivePane.View.NextHeaderFooter
'Goto the footer
Selection.HeaderFooter.LinkToPrevious = False
Selection.WholeStory
Selection.Paste
ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument ' Reset view
End If
End Sub
If I run the code as it is, both the last footer and the footer on the blank page are removed, but if I uncomment the stop command and application.visible = true commands then re-run the code line by line it works perfectly.
Has anyone come across this before? I'm assuming it's an issue with the LinkToPrevious command not unlinking correctly when run through without a break. Is this a timing issue?? Do I need to tell the code to wait at a certain point, if so how would I do that?
As you can see I've even tried to reinsert the footers again with no effect. Any help is greatly appreciated - it appears this one is a bit of a puzzling headwrecker (the best and worst kinds!).
Thanks in advance.
My VBA code is as follows...
Private Sub SetupDuplexEL()
Dim current_page_no As Integer
Dim current_section_no As Integer
'Goto Bookmark and work out page number
ActiveDocument.Bookmarks("BREAK_ELCERT").Select
current_page_no = Selection.Information(wdActiveEndPageNumber)
'Stop
' Application.Visible = True
'Work out if page is odd or even
If current_page_no Mod 2 = 0 Then
' Its Even
' Goto BREAK_ELCERT_2 and insert page breaks
ActiveDocument.Bookmarks("BREAK_ELCERT_2").Select
'Insert Page Breaks
Selection.InsertBreak Type:=wdSectionBreakNextPage
Selection.InsertBreak Type:=wdSectionBreakNextPage
'Set view to the el footer
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageFooter
'Unlink from previous so old footer doesnt become deleted
Selection.HeaderFooter.LinkToPrevious = False
ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument ' Reset View
'Move up
ActiveDocument.Bookmarks("BREAK_ELCERT_2").Select
Selection.MoveDown Unit:=wdLine, Count:=1
'Goto the header and unlink from previous
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
Selection.HeaderFooter.LinkToPrevious = False
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageFooter
'Select contents in footer and remove it from the blank page
Selection.WholeStory
Selection.Copy
Selection.Delete Unit:=wdCharacter, Count:=1
' ********* Word Hack *********** Footer details get deleted so put back in!
ActiveWindow.ActivePane.View.NextHeaderFooter
'Goto the footer
Selection.HeaderFooter.LinkToPrevious = False
Selection.WholeStory
Selection.Paste
ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument ' Reset view
End If
End Sub
If I run the code as it is, both the last footer and the footer on the blank page are removed, but if I uncomment the stop command and application.visible = true commands then re-run the code line by line it works perfectly.
Has anyone come across this before? I'm assuming it's an issue with the LinkToPrevious command not unlinking correctly when run through without a break. Is this a timing issue?? Do I need to tell the code to wait at a certain point, if so how would I do that?
As you can see I've even tried to reinsert the footers again with no effect. Any help is greatly appreciated - it appears this one is a bit of a puzzling headwrecker (the best and worst kinds!).
Thanks in advance.