Detecting existing text in a selection
I'm a novice at VBA so try and not sound too ignorant. I have a situation where I receive a report in standard text. The report has no page breaks only paragraphs, one paragraph per line. I’m taking the report changing it from 8.5”x11” to 8.5”x5.5”, reducing the text size from 10.5 to 7.5 or 8 depending on the report. I can do all this just fine. The trouble comes in when I insert a page break. I count down 36 lines at this point I’m selecting 8 lines and I want to see if any text exists. I don’t care what the text is only if there is any. If there is then I need to search for the text string “Page#” and insert a page break. If there is no text then I need to delete 6 lines to bring the next page up to the top of the sheet. I have no idea how to do the section in red. Below is what I have so far. Any help would be greatly apreciated.
Sub GeoReport_XTB()
' GeoReport Macro
'
'
Application.EnableCancelKey = wdCancelDisabled
Selection.Delete Unit:=wdCharacter, Count:=3
With Selection.PageSetup
.LineNumbering.Active = False
.Orientation = wdOrientLandscape
.TopMargin = InchesToPoints(0.2)
.BottomMargin = InchesToPoints(0.5)
.LeftMargin = InchesToPoints(0.2)
.RightMargin = InchesToPoints(0.2)
.Gutter = InchesToPoints(0)
.HeaderDistance = InchesToPoints(0)
.FooterDistance = InchesToPoints(0)
.PageWidth = InchesToPoints(8.5)
.PageHeight = InchesToPoints(5.5)
.SectionStart = wdSectionNewPage
End With
Selection.EndKey Unit:=wdStory, Extend:=wdExtend
Selection.Font.Name = "Courier New"
Selection.Font.Size = 8
Selection.HomeKey Unit:=wdStory
Selection.MoveUp Unit:=wdLine, Count:=1
Selection.MoveDown Unit:=wdLine, Count:=36
Selection.MoveDown Unit:=wdLine, Count:=8, Extend:=wdExtend
End Sub
Detecting existing text in a selection
As I said I'm new to this. If there is a better way I'm very willing to learn. I've attached two image files and the text file I'm using for testing. Hopefully they help explain a little better. I'm not sure if my image files made it. Please let me know if they didn't.
1 Attachment(s)
Detecting existing text in a selection
I'll try it again My files were to big. It looks like I'll need to do it in three replys.
1 Attachment(s)
Detecting existing text in a selection
Okay this time I made a zip file. I included two images of much better quality and the file after the VBA that I have so far has been run against the original file previous posted. As far as writing the code I've tried so many different things and have come up with nothing that I realy have no idea what to put in. I'm not looking for someone to write the rest of this for me just give me ideas that I can work from.
1 Attachment(s)
Detecting existing text in a selection
Sorry, wrong docx file in the zip file. Attached is the correct one.