-
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules