Hi,
My first post! Hopefully all inline with Forum rules ...
I'm a relatively experienced Excel / VBA user, but I've come across an interesting problem.
I develop/own a large set of workbooks that contain code, and recently users have been complaining that Excel has been hanging, with no way of exiting except for using Task Manager. They are loosing work, and obviously are not too happy with me.
The core of the problem is this: I use the Workbook_SheetActivate() event; the code for this contains the standard code that you can Google for saving and restoring the clipboard contents, to allow users to copy/paste between worksheets:
I should add that I've used this code before without any problems at all. However, I can get my worksheets to hang every time if I do the following:
+ Assume workbook contains a couple of standard worksheet (Sheet1, Sheet2, ...)
+ From Sheet1, type data into a cell, and then CTRL-C to copy the data
+ Click on Sheet 2
+ CTRL-V to paste (note - works fine!)
+ Click on Sheet 1
+ Delete Sheet 1
At this point, as Sheet 1 is deleted, Excel activates Sheet 2, and the SheetActivate() event fires as normal. The code runs OK until .PutInClipboard is called, and then Excel hangs! Actually, it is slighly weirder than that - the code will actually run to the end of the event function (I know, 'cos I put some logging code after those lines), and then it hangs. However, if you step through the code in the VBA editor, this is where the problem is occurring. If I comment out that line then everything is OK.
Some info that is probably relevant; I made a clean / new workbook and put the above minimal code into it, and I got an error message that .PutInClipboard is not implemented!??
What's going on?
I'm using Excel 2010 (Professional Plus 2010, 32-bit, running on Windows 7).
Regards,
Torchwood
My first post! Hopefully all inline with Forum rules ...
I'm a relatively experienced Excel / VBA user, but I've come across an interesting problem.
I develop/own a large set of workbooks that contain code, and recently users have been complaining that Excel has been hanging, with no way of exiting except for using Task Manager. They are loosing work, and obviously are not too happy with me.
The core of the problem is this: I use the Workbook_SheetActivate() event; the code for this contains the standard code that you can Google for saving and restoring the clipboard contents, to allow users to copy/paste between worksheets:
Code:
Set oDataObj = New DataObject
oDataObj.GetFromClipboard
' Main body of sub here
On Error Resume Next
oDataObj.PutInClipboard
Set oDataObj = Nothing
I should add that I've used this code before without any problems at all. However, I can get my worksheets to hang every time if I do the following:
+ Assume workbook contains a couple of standard worksheet (Sheet1, Sheet2, ...)
+ From Sheet1, type data into a cell, and then CTRL-C to copy the data
+ Click on Sheet 2
+ CTRL-V to paste (note - works fine!)
+ Click on Sheet 1
+ Delete Sheet 1
At this point, as Sheet 1 is deleted, Excel activates Sheet 2, and the SheetActivate() event fires as normal. The code runs OK until .PutInClipboard is called, and then Excel hangs! Actually, it is slighly weirder than that - the code will actually run to the end of the event function (I know, 'cos I put some logging code after those lines), and then it hangs. However, if you step through the code in the VBA editor, this is where the problem is occurring. If I comment out that line then everything is OK.
Some info that is probably relevant; I made a clean / new workbook and put the above minimal code into it, and I got an error message that .PutInClipboard is not implemented!??
What's going on?
I'm using Excel 2010 (Professional Plus 2010, 32-bit, running on Windows 7).
Regards,
Torchwood