Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Word Automation Problem

Status
Not open for further replies.

SGLong

Programmer
Joined
Jun 6, 2000
Messages
405
Location
US
I'm doing a VFP Word Automation application where I need to conditionally remove a sentence from one of two paragraphs. By this I mean if the &quot;condition&quot; is True, remove the last sentence from the first paragraph. If the &quot;condition&quot; is false, remove the last sentence from the second paragraph. The trouble I'm having is finding the beginning position of the sentence to remove. my first paragraph is not Word's first paragraph because Word counts a paragraph for each Hard Return that it encounters, which includes the date line, each line of the address, salutation, and blank lines. I'm also doing a fair number of Search/Replaces in this document, like substituting today's date for <MAILING_DATE>, recipients first name for <SALUTATION>, etc.

How do I find where my conditional sentences begin and remove from that point to the end of the paragraph / sentenct?

Steve
 
If you known the ending of the sentence, can you search backwards for a &quot;. &quot; and then assume that is the beginning of the next sentence?

Jim Osieczonek
Delta Business Group, LLC
 
Steve,

If you know the text in the sentence, you can loop through all the sentences until you find it:

FOR EACH loSentence IN loDoc.Sentences
IF loSentence.text = &quot;This is the sentence I am seeking&quot;
* Sentence found
EXIT
ENDIF
ENDFOR

Another possibility: Create a bookmark to encompass the sentence in question. Then do something like this:

oDoc.Bookmarks(1).Range.Delete

I'm not sure if I've got the exact syntax right there, but it should give you a start.

Mike


Mike Lewis
Edinburgh, Scotland
 
Mike,

Your first suggestion looks doable... I'll let you know if it works.

I wish that there was a Help file or some sort of documentation on all these properties and methods. I've got the Hentzenwerke book on Office Automation and VFP which is a good starting point, but it doesn't go into much detail about some of the finer points.

Steve
 
Steve,

Most of what I know about Office Automation, I figured out using the Object Browser in VBA, and (since VFP 7.0 came out) the Intellisense pop-ups.

The Hentzenwerke book is good, but, as you say, it doesn't tell you everything. I don't know of any other book that I could recommend.

Let us know how you get on.

Mike


Mike Lewis
Edinburgh, Scotland
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top