Protect clipboard data from other programs trying to use clipboard at same time?

chuckchuckit

Well-known Member
Joined
Sep 18, 2010
Messages
541
Hello. This is my first post here, so here goes.

I am running an automated macro spreadsheet that every minute or so copies data using the clipboard and pastes it. If before it gets pasted, I use the clipboard to copy something in an other spreadsheet, or other software copies something using the clipboard at the same time, the clipboard contents can get corrupted.

Is there any way to protect the clipboard contents from other programs using the same clipboard area at the same time?

I am assuming there is only one clipboard per computer? What about isolating a program and its clipboard use to a separate core perhaps? (Maybe I am dreaming there...).

I know there are many ways to copy and paste without using the clipboard, but that would make rewritting "a lot" of code. Clipboard protection for each Excel program running would be easier. If there is such a thing.

Thanks. - Chuck
 
Hi Jaafar,

I am now putting the code in the many separate instances of Excel I have that are running macros at the same time. I even pieced in a popup box so I could see when a program is waiting to use the protected clipboard. Your code work runs very well.

There is a problem when I get more than two programs at once that are waiting to use the clipboard. When clipboard becomes available, they all start to use it at once and then they again corrupt the clipboard. I tried having them all check the clipboard more than once before using it, but eventually they use it at the same time again.

So as several or more programs are waiting in line to use the clipboard next, perhaps they would need to somehow be assigned a global number. And if their global number is the lowest number being used, then they would be next in line to use the clipboard. Some sort of way to allocate who is next in line to use the clipboard first.

Maybe some sort of global incrementing so that none try to grab the same number at the same time.

Not sure what might work best there. 3AM here and up in a few hours to work, so off to get some ZZZZ’s for a bit.

Thanks.

Chuck
 
Upvote 0

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
Actually I think looking for a global type array might not be the best way to try to track who should be next to use the clip board. Still always have the problem of two or more happening to be grabbing the same flag at the same time and not knowing who got what for sure (not easily perhaps).

Your very first code that was looking at the "GetClipboardOwner API" might be the way to confirm who is next, if only most recent one trying is such. Can't be two of them I'll bet.

If I do something like get the clipboard protected, do a bit of a pause in case some others did the same thing at the same time. Then check and see if API is mine, if so proceed, if not go back to the waiting for clipboard to be free after whomever got their API there.

I'll play around with the code some and see what variable circumstances might produce. Perhaps that is the better way.

Sometimes walking away from the figuring for a bit, lets the mind come up with new approaches. - At least for this new coder anyway. But it sure is fun/useful when it works.

Thanks.

Chuck
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,777
Messages
6,126,834
Members
449,343
Latest member
DEWS2031

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top