Hi
I have small problem with VBA in word, I have a payslip report exported to word. Unfortunately payslips are not on one page, but there are various number of carrdge returns between them so one payslip can be on two pages. I am looking for a solution (macro) that would move each payslip so that only one would be on each page (for printing purposes). Do you have any ideas?
Code:Option Explicit Sub MakePages() 'Turn off the search and replace dialog message boxes Application.DisplayAlerts = wdAlertsNone 'Begin a new search and replace Selection.Find.ClearFormatting Selection.Find.Replacement.ClearFormatting 'set up to delete multiple blank lines 'the sample text has many lines with a 'single space and a end of paragraph marker 'and lines with six spaces and a para mkr With Selection.Find .Text = " ^p ^p" .Replacement.Text = "" .Forward = True .Wrap = wdFindContinue End With 'delete them Selection.Find.Execute Replace:=wdReplaceAll With Selection.Find .Text = " ^p" .Replacement.Text = "" .Forward = True .Wrap = wdFindContinue End With Selection.Find.Execute Replace:=wdReplaceAll 'set up to search for the word "VALIDATION" that 'indicates the start of a new form. Selection.MoveDown Unit:=wdLine, Count:=1 Selection.Find.ClearFormatting Selection.Find.Replacement.ClearFormatting With Selection.Find .Text = "validation" .Forward = True .Wrap = wdFindAsk .MatchWholeWord = True End With Do While Selection.Find.Execute 'When found move to the start of the line and insert 'a hard pagebreak, Selection.HomeKey Unit:=wdLine Selection.InsertBreak Type:=wdPageBreak 'then move down one line so that the last find is 'not included in the new search Selection.MoveDown Unit:=wdLine, Count:=1 Loop 'quit without prompting when no longer found If Selection.Find.Execute = False Then Exit Sub 'turn ms word alerts back on Application.DisplayAlerts = wdAlertsAll End Sub
---
Ben Van Johnson
This works perfect, thank you very much.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks