How to stop clipboard being cleared by VBA code?

sarujin

New Member
Joined
Oct 1, 2008
Messages
7
All,

I have been developing an excel workbook menu system for my company over the last few months, and currently have encountered an issue regarding the clipboard with copying and pasting.

On every sheet under
Code:
Private Sub Worksheet_Activate
there is some code for generating of that sheets top 3 rows (in these rows there is some hyperlink creation, text resizing etc.

My problem is, if I am on one sheet and I select and copy any data/values, when I click over to a different sheet/tab, the various code in VBA clears the clipboard. Rendering me unable to paste what I have just copied on the prior sheet.

This appears due to the selection changeing, as the visual basic code is run: Currently code like this is enough to 'grey' out the paste button in the excel ribbon.
Code:
Cells(1, 1).Font.Bold = True

Is there anyway around this? maybe even setting the clipboard value at the begining of activating a new worksheet to a variable, and then retrieving on the final line of the vba code?

Regards.
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
you can use a dataobject
Code:
Dim d As DataObject
Set d = New DataObject
d.GetFromClipboard
myclip = d.GetText  ' myclip variable would now contain any text from clipboard
you may need reference to forms2 object library
 
Last edited:
Upvote 0
It looks like sarujin hasn't been around for about six years.

Perhaps you could paste before doing anything else that would clear the clipboard.

Thanks AlphaFrog,

But how can I accomplish this? .. This example summarizes what drives me crazy!:
Sheet1: contains some data
Sheet2: is blank worksheet, but contains this line of code in the initiate event:

Code:
Private Sub Worksheet_Activate()    
ActiveSheet.Range("F6:S6").Orientation = 90
End Sub
When I copy random rows from sheet1, then I click on sheet2 to paste it, the paste button gets grayed out. It appears that the clip board gets cleared if the target worksheet contains any code for formatting cells. Is it a glitch in MS Excel. How can I accomplish copy & paste under these circumstances? .. Thanks
 
Upvote 0
Thanks AlphaFrog,

But how can I accomplish this? .. This example summarizes what drives me crazy!:
Sheet1: contains some data
Sheet2: is blank worksheet, but contains this line of code in the initiate event:

Code:
Private Sub Worksheet_Activate()    
ActiveSheet.Range("F6:S6").Orientation = 90
End Sub
When I copy random rows from sheet1, then I click on sheet2 to paste it, the paste button gets grayed out. It appears that the clip board gets cleared if the target worksheet contains any code for formatting cells. Is it a glitch in MS Excel. How can I accomplish copy & paste under these circumstances? .. Thanks

Can I ask why you want to change the display orientation of that range each time the sheet is activated? Is it necessary to do it every time the sheet is activated? Perhaps there is another way depending on why you need it done.
 
Upvote 0

Forum statistics

Threads
1,216,006
Messages
6,128,236
Members
449,435
Latest member
Jahmia0616

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