Select Body String (with a Table)

F

fred

Doug Robbins has kindly helped with this code and it works great except I
have 2 colum tables as well.

I have SUBJECT line in letter with a 2 column table in some letters
sometimes and Select Range freezes on select.

Is there any way to search "OUR REF:" and make the range select from below
last row table IF TABLE EXISTS else the code executes as it does now still?

Any ideas on how to include the TABLE part please?

Dim Body As Range
Selection.HomeKey wdStory
Selection.Find.ClearFormatting
With Selection.Find
.Text = "Dear"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
Set Body = Selection.Range
Body.End = ActiveDocument.Range.End
'Body.Start = Body.Start + InStr(Body, "Dear")
Body.Start = Body.Start + Len(Body.Paragraphs(1).Range) ' - 1
Body.End = Body.Start + InStr(Body, "Yours") - 1
Body.Select
 
D

Doug Robbins - Word MVP

Sorry, I don't understand what you have. Where is the table in the documnet
if it exists? Where is the "OUR REF:"? Where is the table in relation to
the "OUR REF:"?

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
F

fred

Create Date Field

Mr Jones
2 Jones Road
LONDON

Dear John

Jones v Jones
Court Date: 10 June 2006 THIS line
Your Ref: ABC JEL 3333 THIS line
Our Ref: ABC:08444 THIS line all 3
plus lines could be a 2 column table (nothing like inconsitency!) and Range
selects and stops?

Thank you for coming.

Regards
Bob
 
D

Doug Robbins - Word MVP

I still don't understand what you have, but using a sledgehammer approach

Dim i As Long
With ActiveDocument
If .Tables.Count > 0 Then
For i = .Tables.Count To 1 Step -1
.Tables(i).ConvertToText
Next i
End If
End With


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
F

fred

Hi Doug

Yes the sledgehammer DELETES the entire SUBJECT area but I need to keep the
entire SUBJECT and start selection in same position as macro already does.

I hope this explains more succinctly what I am trying to do with the macro
"Select Body".



A macro is required to delete body of any correspondence with "OUR REF:" as
selection string start (select from next line) and stop before "Yours" case
sensitive - if "Yours" is not case sensitive then if the word appears in the
text it will stop selection and execute too early.



Current macro freezes selection onscreen when a table is used in RE lines of
correspondence.



Current macro is also not case sensitive if it finds "yours" lower case it
executes.



Is it possible to refine the macro which works great to deal with these in
its selection range?



A 2 column table in START selection and still select as it does and not
freeze on screen

End selection case sensitive "Yours" not "yours"



Really appreciate the help -I've been trying this macro all week and these
are the two things I need to fix.





{CREATEDATE \@ "d MMMM yyyy" \* MERGEFORMAT}10 December 2007





Mr John Smith

22 Smith Road

LONDON UK





Dear John



JONES v JONES

COURT DATE:
10 JUNE 2006

YOUR REF:
ABC DEF 1333

OUR REF:
ABC:ZZC:601234




or RE could be typed without using a 2 Column Table

JONES v JONES

COURT DATE: 10 JUNE 2006

YOUR REF: ABC:DEF:1333

OUR REF: ABC:ZZC:601234



The quick brown fox jumps over the lazy dog. The quick brown fox jumps over
the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown
fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog.





The quick brown fox jumps over the lazy dog. The quick brown fox jumps over
the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown
fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog.



Yours faithfully

XXXXXXXXXXX







Fred Smith

Partner



Hope this is a little clearer.
 
F

fred

Doug,
Apologies, I changed the line of code in original macro (refinement) to "Our
Ref" and not "Dear"

With Selection.Find
.Text = "Our Ref:"

was previously "Dear".
 
F

fred

This is where I am at now:
Doug this is the error I receive with a Table in subject



RUNTIME ERROR 5904 cannot edit range END DEBUG HELP



I just want to delete the body text string only.



Public Sub BodySelectPaste()

Dim Body As Range

Selection.HomeKey wdStory

Selection.Find.ClearFormatting

With Selection.Find

.Text = "Our Ref"

.Replacement.Text = ""

.Forward = True

.Wrap = wdFindContinue

.Format = False

.MatchCase = False

.MatchWholeWord = False

.MatchWildcards = False

.MatchSoundsLike = False

.MatchAllWordForms = False

End With

Selection.Find.Execute

Set Body = Selection.Range

Body.End = ActiveDocument.Range.End

'Body.Start = Body.Start + InStr(Body, "Our Ref")

Body.Start = Body.Start + Len(Body.Paragraphs(1).Range) + 1

Body.End = Body.Start + InStr(Body, "Yours") - 1

Body.Select

Body.Delete

Body.InsertParagraph

With Selection.ParagraphFormat

.KeepWithNext = False

.KeepTogether = False

End With

Selection.Paste

End Sub



11 November 2006





Mr John Smith

22 Smith Road

LONDON UK



Dear Sir



JONES v JONES

COURT DATE: 10 JUNE 2006

DATE OF SUMMONS: 27 NOVEMBER 2006

YOUR REF: ABC:HIJ:1333

OUR REF: ABC:601234



Thank you for coming. If yours is okay then that is good.

Thank you for going.

Yours faithfully

XXXXXXXXXXXXXXXXXXX







Author

Title



Again thank you for any help Doug.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top