Class Event CutCopyMode help

winxpdows

New Member
Joined
Apr 21, 2011
Messages
24
Hi All,

Looking for help from the experts. I am unable to copy/cut/paste between workbooks. I'm fairly certain it is because of a Class event I have to check if the workbook has been changed, but can't figure out a workaround.

I am building an addin that makes a custom toolbar of icons for running different procedures. I only want certain buttons available on certain types of worksheets (that contain specific data in the header) that the users have as templates. To do so, I found online postings leading me to create a Class Event

Code:
Public WithEvents App as Application

Private Sub App_WorkbookActivate(ByVal Wb as Workbook)
   call statuscheck
End Sub

where statuscheck is my procedure that looks in the header for the correct info and enables/disables the correct buttons

in my workbook_open I call a routine named InitiateWorkbookChangeEvent..

Code:
dim myobject as New CExcelEvents

Sub InitiateWorkbookChangeEvent()
   Set myobject.App = Application
End Sub

It works great for enabling/disabling the buttons, but if I need the users to still be able to copy and paste between different workbooks. Copy and pasting within the same workbook works fine. But if you copy something, as soon as you click on another workbook, the flashing outline of the selection you want to copy in the other workbook disappears.

If there is a different way for me to catch when a user changes workbooks so that I enable the correct buttons, I'd appreciate that help as well.

Thank you in advance!
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
Oh.. And I have tried grabbing the cutcopymode before the call statuscheck to try and enable it again after the statuscheck. But by then it already says it's 0.

Any help is greatly appreciated!
 
Upvote 0
Thanks Jaafar for directing me there.. Unfortunately, I still can't get it working for my add-in...

I've tried adding the code you posted there into my Class Module and I get a compile error...

Code:
Public WithEvents App as Application

Private Sub App_WorkbookActivate(ByVal Wb as Workbook)
    call xlCalcMan  
    call statuscheck
End Sub

I tried adding it to my ThisWorkbook module but it's not working that way either... and I've tried putting the xlCalcMan/Auto procedures into regular modules as public routines... No luck...

any other ideas would be GREATLY appreciated. Thanks in advance!
 
Upvote 0
Try amending your Class module code as follows and see if it works:

Code:
[B][COLOR=Magenta]Private Declare Function OpenClipboard Lib "User32" _
(ByVal hwnd As Long) As Long[/COLOR][/B]
 
[B][COLOR=Magenta]Private Declare Function CloseClipboard Lib "User32" () As Long
[/COLOR][/B]
Public WithEvents App as Application

Private Sub App_WorkbookActivate(ByVal Wb As Workbook)

   [B][COLOR=Magenta]OpenClipboard 0[/COLOR][/B]
   Call statuscheck
   [B][COLOR=Magenta]CloseClipboard[/COLOR][/B]
   
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,574
Messages
6,179,629
Members
452,933
Latest member
patv

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