Consulting

Results 1 to 4 of 4

Thread: worksheet events issue

  1. #1
    VBAX Mentor ALe's Avatar
    Joined
    Aug 2005
    Location
    Milan
    Posts
    383
    Location

    worksheet events issue

    Hi all!

    Is there a way to understand which kind of event occured on a worksheet?

    I'm trying to trigger an event if the user press "Copy" or tries to copy any cell of the activesheet.

    colud it be, associated with selection_change,
    [VBA]if application.cutcopymode=true then
    'do it
    else
    do nothing
    end if[/VBA]
    ?

  2. #2
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Hi Ale,
    "True" doen't work for me, so maybe that is your problem too.
    try
    [vba]
    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    If Application.CutCopyMode = 1 Then
    MsgBox "Someone is trying to copy this"
    Application.CutCopyMode = 0
    End If
    End Sub
    [/vba]
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  3. #3
    Administrator
    Chat VP VBAX Guru johnske's Avatar
    Joined
    Jul 2004
    Location
    Townsville, Australia
    Posts
    2,872
    Location
    If you just want to stop them copying...

    [VBA]
    Option Explicit

    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    Application.CutCopyMode = Not Application.CutCopyMode
    End Sub
    [/VBA]
    You know you're really in trouble when the light at the end of the tunnel turns out to be the headlight of a train hurtling towards you

    The major part of getting the right answer lies in asking the right question...


    Made your code more readable, use VBA tags (this automatically inserts [vba] at the start of your code, and [/vba ] at the end of your code) | Help those helping you by marking your thread solved when it is.

  4. #4
    VBAX Mentor ALe's Avatar
    Joined
    Aug 2005
    Location
    Milan
    Posts
    383
    Location
    they don't work. Both codes are triggered when the change of selection has been made.

    To understand what I mean try to select copy then activate another workbook and select paste. The code won't be executed.

Posting Permissions

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