clipboard .GetText behaviour

L

Larry Sulky

Word 2003 SP3

Someone please repeat my experiment in Word:

1. Create a paragraph in Word with the content "abcd". Duplicate the
paragraph so you have two of them consecutively.

2. Select and copy into the clipboard the first short paragraph,
INCLUDING the paragraph marker. Run the testclipper macro (below) and
note the reported length of the string from the clipboard. I get a
length of 4 and a final character decimal value of 100 (the code for
"d"). When I close the msgbox I find that the copied string has been
inserted WITHOUT the paragraph marker. What do you get?

3. Undo the text insertion, then select and copy the same paragraph,
but WITHOUT the paragraph marker this time. Run testclipper again. I
get the exact same result as in step 2. What do you get?

4. Undo the text insertion, then select and copy both paragraphs
together, INCLUDING the final paragraph marker. Run testclipper again.
I get a length of 12, and a final character decimal value of 10 (the
paragraph marker code). When I close the msgbox I find that the copied
string has been inserted WITH the paragraph marker. What do you get?

5. Undo the text insertion, then select and copy both paragraphs
together, WITHOUT the final paragraph marker. Run testclipper again. I
get the same result as in step 4, even though the final paragraph
marker was not included in the copied text. What do you get?

These tests suggest that:

A) If only a single paragraph is copied into the clipboard, .GetText
will not retrieve the closing paragraph marker, although simply
pasting the paragraph, instead of capturing its text and inserting it,
will bring the paragraph marker along. It will report a length without
the paragraph marker, regardless of whether the paragraph marker was
included in the copy.

B) If more than one paragraph is copied into the clipboard, the
reported length will be the actual length of the paragraphs including
their paragraph markers, plus one for each paragraph. And .GetText
WILL retrieve the paragraph markers and will even add one at the very
end if one was not present.

This all means that if I need to capture the text in the clipboard and
evaluate or process it in some way, I cannot know whether a paragraph
return was included as the final character. If I find a paragraph
return character before the end of the clipboard value, then I know
that there will also be a paragraph return at the very end regardless
of whether the user actually copied it into the clipboard; and if I
find no paragraph marker anywhere in the clipboard value, then I know
that the user selected anything up to AND INCLUDING one entire
paragraph, but I can't know whether there was a final paragraph marker
in the clipboard.

Does this jibe with what others see? Anybody know a way around this
problem? This isn't a theoretical exercise -- a crucial function that
I have to develop relies on it.

Thanks for any insights ....

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Sub testclipper()
Dim myTargetText As String
Dim myData As DataObject
Dim strClip As String
Set myData = New DataObject
myData.GetFromClipboard
strClip = myData.GetText
MsgBox "Length: " & Len(strClip) & vbCrLf & _
"Final char (dec.): " & AscW(Right(strClip, 1)), , "DEBUG"
Selection.Collapse wdCollapseStart
Selection.TypeText strClip
End Sub
 

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