Insert Page Break

Help with writing and playing macros

Insert Page Break

Postby philbert » Fri Jun 22, 2007 3:29 pm

I have a situation that Have no idea how to get started on it. The reports that we print are printed in Landscape. Sometimes the text per page exceed the 45 lines so the text rolls over to the next page. Well this throws off the rest of the report. The only common piece of text is the word Page#. I'd like to search for that text when it's found move up one line and insert a page break. Hopfully this will fource a new page to be created. Can this be done? :?:
User avatar
philbert
Newbie
 
Posts: 3
Joined: Mon Jun 18, 2007 11:00 pm

Re: Insert Page Break

Postby Mofi » Sat Jun 23, 2007 11:13 am

If you press the button Help on any Find/Replace dialog you will see a small table with special characters. One of the lines is:

^b matches a page break

The rest is simple:

InsertMode
ColumnModeOff
HexOff
UnixReOff
Top
Find MatchCase RegExp "%^([~^b]*Page[ ^t]++[0-9]^)"
Replace All "^b^1"

Add UnixReOn or PerlReOn (v12+ of UE) at the end of the macro if you do not use UltraEdit style regular expressions by default - see search configuration. Macro command UnixReOff sets the regular expression option to UltraEdit style.

The regular expression search string is probably more complex as necessary for your file, but I don't know the format of the line which contains the page number.
User avatar
Mofi
Grand Master
Grand Master
 
Posts: 4036
Joined: Thu Jul 29, 2004 11:00 pm
Location: Vienna

Re: Insert Page Break

Postby philbert » Mon Jun 25, 2007 8:03 pm

Very cool. That's almost perfect. It inserts a page break at the ver top that prints out a blank sheet. So I'm going to see if I can figure out how to work around that before I ask the forum.

Thanks agains
User avatar
philbert
Newbie
 
Posts: 3
Joined: Mon Jun 18, 2007 11:00 pm

Re: Insert Page Break

Postby philbert » Tue Jun 26, 2007 3:02 pm

I need to find the text "Page#" move up one line insert a page break then find the next string "Page#". The problems I run into so far is if you find the text move up one line it will find the same line of text and put inself in to and endless loop. If you put Find "Page#" twice it works until it gets to the end of the file then goes in to an endless loop. To make it even funner after I insert the page breaks I need to find "Page#" [0-9]+ and replace it with "". Here is what I have for code.

InsertMode
ColumnModeOff
HexOff
UnixReOff
Top
Find "Page#"
Key UP ARROW
InsertPageBreak
Find RegExp "Page# [0-9]+"
Replace All ""

Here is a sample of the first page of the report header.

Code: Select all
1)
2)06/08/2007              WY PRA-YELL 103(1)                            Page# 1     
3)                           North Rim and Canyon Area Roads
4)                              Grandview Parking Area
5)                             SLOPE STAKE REPORT (m )

The number in front of the ) are not in the report I'm just showing the line numbers.

Thanks
User avatar
philbert
Newbie
 
Posts: 3
Joined: Mon Jun 18, 2007 11:00 pm

Re: Insert Page Break

Postby Mofi » Fri Jun 29, 2007 7:06 am

I don't know why you make it so complicated. Look on following macro:

InsertMode
ColumnModeOff
HexOff
UnixReOff
Top
Find MatchCase RegExp " Page# ++[0-9]+"
Replace ""
Find MatchCase RegExp "%^([~^b]*^) Page# ++[0-9]+"
Replace All "^b^1"
Find MatchCase RegExp " Page# ++[0-9]+"
Replace All ""

The macro first searches from top of the current file for the first page number and simply deletes it without inserting a page break because you surely do not want an empty page at start of the file.

The second search and replace is a replace ALL. It inserts the page break at start of the line with the page number (= after end of the line above) and at the same time deletes the page number.

Execute this macro once and the job should be done.

[~^b] makes sure not to insert a page break when there is already one. The last replace all deletes only the page number for those lines where a page break already existed. If your file never contains a page break before macro execution, you can also use the following macro:

InsertMode
ColumnModeOff
HexOff
UnixReOff
Top
Find MatchCase RegExp " Page# ++[0-9]+"
Replace ""
Find MatchCase RegExp "%^(*^) Page# ++[0-9]+"
Replace All "^b^1"
User avatar
Mofi
Grand Master
Grand Master
 
Posts: 4036
Joined: Thu Jul 29, 2004 11:00 pm
Location: Vienna


Return to Macros