PDA

View Full Version : Solved: @ TinBendr 'delete everything but'



blackie42
04-04-2008, 07:28 AM
Hi

Thanks for creating the code for my sorting problem. Could you help with just one more thing. The code does delete all records apart from those with the (G) but it also deletes the line spacing. I have tried recording and inserting a line(or is it referred to as a paragraph?) between records but because I'm not familiar with word VBA I can't translate it in to proper code.

thanks again

Jon

Tinbendr
04-07-2008, 01:37 PM
Sorry, I haven't responded before now. I've been out of town.

Sub Seperate_G_Records2()
Dim aDoc As Document
Dim bDoc As Document
Dim AllRng As Range
Dim SrchRng As Range
Set aDoc = ActiveDocument
Set bDoc = Documents.Add
'easier to read in landscape
With bDoc.PageSetup
.Orientation = wdOrientLandscape
End With

Set AllRng = aDoc.Range
Set SrchRng = AllRng.Duplicate
Do
SrchRng.Find.Execute findtext:="(G)", Wrap:=wdFindStop
If SrchRng.Find.Found Then
SrchRng.MoveStart wdParagraph, -2
bDoc.Range.InsertAfter SrchRng.Text & vbCr & vbCr
SrchRng.MoveStart wdParagraph, 3
SrchRng.End = AllRng.End
Application.StatusBar = "Approx " & Format((SrchRng.Start _
/ AllRng.End) * 100, "##") & "% complete"
End If
Loop Until Not SrchRng.Find.Found

'set font
Set AllRng = bDoc.Range
With AllRng.Font
.Name = "Courier New"
.Size = 8
End With
End Sub

blackie42
04-08-2008, 01:28 AM
Thanks very much for your help - this will save a lot of messing about

regards

Jon