PDA

View Full Version : Enable paste



ukphoenix
07-17-2008, 12:46 AM
I have a dilemma, I have a button that enables and disables the cutcopypaste features by toggling it true or false. The problem I have is it will only allow me to copy and paste within the same workbook.

What would i need to do or change to allow the clipboard (copied stuff) to be copied from one workbook and pasted in another


Sub ToggleCutCopyAndPaste(Allow As Boolean)
'Activate/deactivate cut, copy, paste and pastespecial menu items
Call EnableMenuItem(21, Allow) ' cut
Call EnableMenuItem(19, Allow) ' copy
Call EnableMenuItem(22, Allow) ' paste
Call EnableMenuItem(755, Allow) ' pastespecial
Application.CommandBars("Worksheet Menu Bar").Controls("Tools").Controls("Macro").Enabled = False
Application.CommandBars("Worksheet Menu Bar").Controls("Insert").Enabled = True
Application.CommandBars("Worksheet Menu Bar").Controls("Edit").Enabled = True
Application.CommandBars("Worksheet Menu Bar").Controls("format").Enabled = True
Application.CommandBars("Worksheet Menu Bar").Controls("data").Enabled = True
Application.CommandBars("Worksheet Menu Bar").Controls("Tools").Enabled = True

'Activate/deactivate drag and drop ability
Application.CellDragAndDrop = Allow

'Activate/deactivate cut, copy, paste and pastespecial shortcut keys
With Application
Select Case Allow
Case Is = False
.OnKey "^c", "CutCopyPasteDisabled"
.OnKey "^v", "CutCopyPasteDisabled"
.OnKey "^x", "CutCopyPasteDisabled"
.OnKey "+{DEL}", "CutCopyPasteDisabled"
.OnKey "^{INSERT}", "CutCopyPasteDisabled"
Case Is = False
.OnKey "^c"
.OnKey "^v"
.OnKey "^x"
.OnKey "+{DEL}"
.OnKey "^{INSERT}"
End Select
End With
End Sub

Sub EnableMenuItem(ctlId As Integer, Enabled As Boolean)
'Activate/Deactivate specific menu item
Dim cBar As CommandBar
Dim cBarCtrl As CommandBarControl
For Each cBar In Application.CommandBars
If cBar.Name <> "Clipboard" Then
Set cBarCtrl = cBar.FindControl(ID:=ctlId, recursive:=True)
If Not cBarCtrl Is Nothing Then cBarCtrl.Enabled = Enabled
End If
Next
End Sub

Bob Phillips
07-17-2008, 01:20 AM
Your case statement tests for False in both cases!

ukphoenix
07-17-2008, 03:56 AM
So what bit needs to read true for the paste feature to work and allow me to paste into another workbook

Bob Phillips
07-17-2008, 04:50 AM
No idea, as I don't know what Allow is or where it comes from.

Bob Phillips
07-17-2008, 04:57 AM
Taking a guess, I suppose it could be



With Application
Select Case Allow
Case Is = False
.OnKey "^c", "CutCopyPasteDisabled"
.OnKey "^v", "CutCopyPasteDisabled"
.OnKey "^x", "CutCopyPasteDisabled"
.OnKey "+{DEL}", "CutCopyPasteDisabled"
.OnKey "^{INSERT}", "CutCopyPasteDisabled"
Case Is = True
.OnKey "^c"
.OnKey "^v"
.OnKey "^x"
.OnKey "+{DEL}"
.OnKey "^{INSERT}"
End Select
End With

ukphoenix
07-17-2008, 07:57 AM
tried your suggestion but still not able to copy from workbook and paste in another.
Attached is the files for you to look at. I need to copy from test1 workbook and paste into OT workbook. (both workbooks within the zip)

The password for the enable button = tracker.

ukphoenix
07-17-2008, 02:52 PM
Bump!! could really do with some brain behind this, i just cant see why its not working