Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / November 2006

Tip: Looking for answers? Try searching our database.

Select Body String (with a Table)

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
fred - 11 Nov 2006 02:37 GMT
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
Doug Robbins - Word MVP - 11 Nov 2006 02:59 GMT
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:"?

Signature

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

> Doug Robbins has kindly helped with this code and it works great except I
> have 2 colum tables as well.
[quoted text clipped - 30 lines]
> Body.End = Body.Start + InStr(Body, "Yours") - 1
> Body.Select
fred - 11 Nov 2006 04:37 GMT
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

> 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
[quoted text clipped - 34 lines]
>> Body.End = Body.Start + InStr(Body, "Yours") - 1
>> Body.Select
Doug Robbins - Word MVP - 11 Nov 2006 06:15 GMT
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

Signature

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

> Create Date Field
>
[quoted text clipped - 54 lines]
>>> Body.End = Body.Start + InStr(Body, "Yours") - 1
>>> Body.Select
fred - 11 Nov 2006 10:21 GMT
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.

>I still don't understand what you have, but using a sledgehammer approach
>
[quoted text clipped - 65 lines]
>>>> Body.End = Body.Start + InStr(Body, "Yours") - 1
>>>> Body.Select
fred - 11 Nov 2006 10:29 GMT
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".

> Hi Doug
>
[quoted text clipped - 147 lines]
>>>>> Body.End = Body.Start + InStr(Body, "Yours") - 1
>>>>> Body.Select
fred - 11 Nov 2006 11:05 GMT
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.

> Doug,
> Apologies, I changed the line of code in original macro (refinement) to
[quoted text clipped - 156 lines]
>>>>>> Body.End = Body.Start + InStr(Body, "Yours") - 1
>>>>>> Body.Select
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.