Logandouglas
02-02-2015, 03:40 PM
Hey all, I've been trying to crack out a macro to automatically reformat a document after being imported into word. I've so far managed to reformat the page and put a header in the first page. Since I made the header I now have redundant information on the subsequent pages that I want to get rid of. Is there a way to find just the page breaks and delete the next 13 "paragraphs" as denoted by the symbol in formatting? The document is an unknown number of pages and I've had to pull together bits and pieces of information from around the web. The problem is, the loop keeps detecting simple paragraph returns instead of page breaks, regardless of what I put in the .text = "" and thus deletes random chunks of my documents. Any advice would be greatly appreciated.
Dim i As Integer
Dim pgCount As Integer
pgCount = ActiveDocument.ActiveWindow.ActivePane.Pages.Count
Selection.HomeKey Unit:=wdStory
i = 1
Do While (i < pgCount)
i = i + 1
With ActiveDocument.Range.Find
.Text = Chr(12)
.Wrap = wdFindContinue
End With
Selection.Find.Execute
Selection.MoveRight Unit:=wdCharacter, Count:=2
Selection.MoveDown Unit:=wdLine, Count:=13, Extend:=wdExtend
Selection.Delete
Loop
Dim i As Integer
Dim pgCount As Integer
pgCount = ActiveDocument.ActiveWindow.ActivePane.Pages.Count
Selection.HomeKey Unit:=wdStory
i = 1
Do While (i < pgCount)
i = i + 1
With ActiveDocument.Range.Find
.Text = Chr(12)
.Wrap = wdFindContinue
End With
Selection.Find.Execute
Selection.MoveRight Unit:=wdCharacter, Count:=2
Selection.MoveDown Unit:=wdLine, Count:=13, Extend:=wdExtend
Selection.Delete
Loop