Hello all, sorry for not responding... I've been away and another bit of my code had my attention.
The txtrange object is not the name of a text area or box, it is an Ihtmltxtrange object. I have the truncation problem solved, using .movetoend and doing some basic algebra to calculate x and y type values. This works pretty well.
I need to figure out a way to capture the first and last words of the selection, so I will be trying the solution given above in a day or two, but before that, I have discovered an interesting problem.
If I set a txtrange and retrieve the .htmltext, the retrieval process automatically appends the relevant closing tag, even if your selection did not include the closing tag to begin with. Very frustrating given that I would like to replace only the .htmltext selected. See, you cannot use a find and replace function like with the "Scripting.FileSystemObject" because the source string NEVER matches the text for which you are searching. Example... say you select the text "The quick brown" out of the sentence "The quick brown fox." The underlying HTML may look like this <tag>The quick brown fox.</tag>. Therefore, your selection (if you use txtrange.htmltext) should appear as <tag>The quick brown, but oh no, it actually appears as <tag>The quick brown</tag>. This is because the .htmltext property follows some kind of compliance rules that demans the text always be captured as valid HTML. Now, you can see why the selected text string never matches if you search for that string in the source document.
Okay, so I will use .text instead. After all, if you append tags in HTML, as long as they are complete and correct, you can insert them just about anywhere without negatively altering the document. Well, here's something interesting. Sometimes, the .text string is not recognized. Imagine it like this... you highlight some text on a webpage, again "The quick brown fox" for example, then you open that webpage in notepad and do a search for that very text. Only you get a message that the text cannot be found. So then, you manually find the text in the document. It looks the same so you even paste the original text you copied into the document on a line right above or below the source text. Again, they look identicle, character for character, but the find dialog in notepad doesn't recognize the text you copied from the page. That is very frustrating and seems to make using something like streamwriter very unreliable.
Therefore, if someone can recommend a way to search for a string in a text document and replace that string that they know is 100% effective, I would be grateful to hear of it.
I will post the results of my test of the code above when I have tested it.
Thanks all for looking.
-gk