Consulting

Page 2 of 2 FirstFirst 1 2
Results 21 to 26 of 26

Thread: Disable Cut, Copy, Paste Macro for One Column

  1. #21
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    Show me the Workbook's BeforeClose and BeforeSave Codes
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

  2. #22
    Knowledge Base Approver VBAX Wizard
    Joined
    Apr 2012
    Posts
    5,646
    I think you'd better stick to:


    [vba]Sub ChkSelection(ByVal Sh As Object) [/vba]
    [vba]

    Select Case Sh.Name
    Case "CLIENTE PN"
    ToggleCutCopyAndPaste Intersect(Selection, Sh.Columns(15)) Is Nothing
    Case "CLIENTE PJ"
    ToggleCutCopyAndPaste Intersect(Selection, Sh.Columns(13)) Is Nothing
    Case "CONCESIONARIOS"
    ToggleCutCopyAndPaste Intersect(Selection, Sh.Columns(10)) Is Nothing
    Case "PROVEEDORES"
    ToggleCutCopyAndPaste Intersect(Selection, range(Sh.Columns(13),Sh.Columns(17)) Is Nothing
    Case "EMPLEADOS"
    ToggleCutCopyAndPaste Intersect(Selection, Sh.Columns(16)) Is Nothing
    Case Else
    ToggleCutCopyAndPaste True
    End Select

    End Sub
    [/vba]
    Last edited by snb; 05-20-2013 at 02:27 AM.

  3. #23
    SamT:

    I have only BeforeClose sub:

    [VBA]Option Explicit
    Private Sub Workbook_Activate()
    ActiveSheet.Range("A6").Select
    Application.CellDragAndDrop = False

    End Sub

    Private Sub Workbook_BeforeClose(Cancel As Boolean)
    ToggleCutCopyAndPaste False
    Application.CellDragAndDrop = True
    End Sub

    Private Sub Workbook_Deactivate()
    ToggleCutCopyAndPaste True
    Application.CellDragAndDrop = True
    End Sub

    Private Sub Workbook_Open()
    ActiveSheet.Range("A6").Select
    Application.CellDragAndDrop = False
    End Sub

    Private Sub Workbook_SheetActivate(ByVal SH As Object)
    ChkSelection SH
    End Sub

    Private Sub Workbook_SheetSelectionChange(ByVal SH As Object, ByVal Target As Range)
    ChkSelection SH
    End Sub

    ... continue rest of Sub's...

    [/VBA]
    Snb:

    Getting a red line (error compilation) in
    [VBA]
    Case "PROVEEDORES"
    ToggleCutCopyAndPaste Intersect(Selection, range (Sh.Columns(13),Sh.Columns(17)) Is Nothing
    [/VBA]

    And previously tried, with no result (nothing happens, no CutCopyAndPaste control):

    [VBA]ToggleCutCopyAndPaste Intersect(Selection, (Sh.Columns(13)),Sh.Columns(17)) Is Nothing[/VBA]

  4. #24
    Knowledge Base Approver VBAX Wizard
    Joined
    Apr 2012
    Posts
    5,646
    I hardly believe that, but:

    [VBA]
    ToggleCutCopyAndPaste Intersect(Selection, Range("O:O,Q:Q")) Is Nothing
    [/VBA]

  5. #25
    Snb:

    Now it's working and is a more simple code

    thank you

  6. #26
    VBAX Newbie
    Joined
    May 2016
    Posts
    1
    Location
    I wish to disable the cut, paste and copy functions in my workbook executed by the user. I have inserted the module shown in the original post dated 5/5/2008 in this thread. It works! Except for one circumstance. My program can import worksheets from two separate types of Excel files. The first type is a file that does not contain the ToggleCutCopyAndPaste module. The second type does contains the ToggleCutCopyAndPaste module. When my program opens the file type that does not have the "ToggleCut..." module, everything works properly. However, when my program opens the Excel file that does have the ToggleCutCopyAndPaste module, a problem arises. My copy and insert worksheet routine appears to work properly. That is, the file is inserted into the current workbook just as expected. But, when focus is back on the current workbook and I execute any of the copy, cut or paste commands, the file from which the worksheet was copied, is opened; execution of that file's "ThisWorkbook" code begins and eventually crashes. It appears that something is getting imported with the worksheet, but I don't know what.

    Curiously, if I save the file and reopen it, it works properly. Even more curious is, immediately after the offending "insert routine" is executed, if I go to any other application (such as NotePad) and perform a Copy Command, Excel crashes.

    Can anyone suggest a fix for this or offer any insight?

    Thanks,
    KenS

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •