Clipboard Woes

M

MT DOJ Help Desk

Word 2000

I have a macro that passes data to and from the clipboard. I have a problem
in that the contents of the clipboard seem to be changing unexpectedly. In
the code below I've marked the lines where the change seems to happen. If I
put a watch on cbLocate and step through the code, it contains one value the
first time CheckClipboard is run, and a different value the second time
CheckClipboard runs. The subroutines below are shown in their entirety.

****************

Sub RemoveLocate()

SelectLocate <<< This calls a subroutine that just selects
text in the document.
Selection.MoveRight Unit:=wdCharacter, Count:=1, Extend:=wdExtend
CheckClipboard
Selection.Delete Unit:=wdCharacter, Count:=1 <<< This
command seems to change the clipboard contents.
CheckClipboard
NextLocate <<< This calls a subroutine that goes to the
next block of text in the document.

End Sub

Sub CheckClipboard()

ReadFromClipboard
If InStr(1, cbLocate, "LOCATED RECORD NOTIFICATION",
vbBinaryCompare) Or _
InStr(1, cbLocate, "$L", vbBinaryCompare) Then
PasteLocate
End If

End Sub

Sub ReadFromClipboard()

Set cbValue = New DataObject
cbValue.GetFromClipboard
cbLocate = Trim(cbValue.GetText)

End Sub

****************

As indicated above, it seems to be the Selection.Delete command that is
changing the clipboard contents. This makes a certain amount of sense if
the block of text is being cut from the document. Is there a way to delete
blocks of text without the data landing on the clipboard? Is there
something about the clipboard that I don't understand that might be causing
this problem, like maybe the clipboard is storing multiple blocks of text
and my code isn't handling that properly? Also, I understand that data
objects can hold multiple pieces of information. Could the data object be
the problem?

I apologize if this is all too vague, but I thought that trying to post my
complete set of macros, or explain the fine details of everything that I'm
doing, would be too confusing, so I've tried to boil it down to the section
of code where I'm seeing the problem (although, I know this might just be a
symptom, and the real problem might be elsewhere in my code).

Any help you can offer will be greatly appreciated.

--Tom
 
J

Jezebel

VBA doesn't give you much choice in how you handle the clipboard (unlike
VB). But why are you using the clipboard here at all? If you need to move or
copy text from one place to another within Word, there are much easier ways
to do it (like copying the range relevant range object).
 
M

MT DOJ Help Desk

I'm not moving data within Word. I'm copying a block of text, processing it
to pull out particular data, and writing that data to the clipboard so that
I can manually switch over to another application and paste the data into a
form. The other application I'm dealing with is a law enforcement system
that is very weak in terms of its automation capabilities, so the last part
has to be done manually.

You might wonder why I'm copying a whole block of text and then pulling out
the data I need instead of just locating the data in the Word document and
copying it from there. Basically, there's an evolution of processes
involved here. I have another feature that MUST copy the entire block of
text. So when I went to add my newest feature I realized that I could just
feed the block of text into a string variable, pull out the data with a
INSTR() function, and write it to the clipboard.

--Tom
 

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