+ Reply to Thread
Results 1 to 7 of 7

Detecting a PASTE event related to a UserForm TextBox.

Hybrid View

  1. #1
    Registered User
    Join Date
    10-25-2012
    Location
    Washington DC
    MS-Off Ver
    For MS 365
    Posts
    54

    Detecting a PASTE event related to a UserForm TextBox.

    I have a UserForm with a TextBox on it that allows the user to input up to 1,000 characters of notes. There are certain characters that are not allowed such as slashes, parens, ampersands, etc. I have a function that keeps these characters out (using the KeyPressed event) but, I would like to be able to detect when the user has used "paste" to populate the TextBox. The Keypressed event only fires when the user types the information in manually.

    I suppose I can step through the contents of the TextBox character by character everytime the content changes, but isn't there a way to detect a "paste" event instead?

    Thanks.

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,644

    Re: Detecting a PASTE event related to a UserForm TextBox.

    Perhaps you could use the BeforeDropOrPaste event of the textbox.
    If posting code please use code tags, see here.

  3. #3
    Registered User
    Join Date
    10-25-2012
    Location
    Washington DC
    MS-Off Ver
    For MS 365
    Posts
    54

    Re: Detecting a PASTE event related to a UserForm TextBox.

    Thanks Norie.

    Not to seem lazy but, would you have time to shed some light on how to implement that event?

  4. #4
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,644

    Re: Detecting a PASTE event related to a UserForm TextBox.

    What do you mean 'implement'?

    If you mean process what's being pasted then you can get that via the Data parameter of the event.

  5. #5
    Registered User
    Join Date
    10-25-2012
    Location
    Washington DC
    MS-Off Ver
    For MS 365
    Posts
    54

    Re: Detecting a PASTE event related to a UserForm TextBox.

    I think I can deal with writing the code that I want to process once this event is detected.

    I created the sub like I believe it needs to be per the syntax listed in the vba help section, but I get an error. I was hoping for some help with the actual sytax of sub.

    Thanks.

  6. #6
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,644

    Re: Detecting a PASTE event related to a UserForm TextBox.

    How did you create the sub?

    The easiest way is to select the textbox from the left hand dropdown above the code window and then pick the event, BeforeDropOrPaste in this case, from the right hand dropdown.

    If you do that you'll end up with something like this, oviously the TexBox1 bit will change to reflect the name of your textbox.
    Private Sub TextBox1_BeforeDropOrPaste(ByVal Cancel As MSForms.ReturnBoolean, ByVal Action As MSForms.fmAction, ByVal Data As MSForms.DataObject, ByVal X As Single, ByVal Y As Single, ByVal Effect As MSForms.ReturnEffect, ByVal Shift As Integer)
    
    End Sub

  7. #7
    Registered User
    Join Date
    10-25-2012
    Location
    Washington DC
    MS-Off Ver
    For MS 365
    Posts
    54

    Re: Detecting a PASTE event related to a UserForm TextBox.

    Thank you again Norie.

    I had a typo in before. As usual, couldn't see the forest for the trees.

    It works great now.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Stop exit event of textbox firing when click a command button to close a userform
    By chrisjames25 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-18-2013, 09:27 AM
  2. [SOLVED] Is it possible to have a command button click event autofill a textbox within a userform?
    By Orestees in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-16-2012, 02:14 PM
  3. Userform Textbox Exit Event to Run Application
    By baisty182 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-29-2010, 12:30 PM
  4. Userform textbox event that fires after I exit the textbox
    By jerseyguy1996 in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 02-04-2010, 08:08 AM
  5. Copy/Paste from worksheet to textbox in userform
    By jarrods in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 07-06-2009, 05:52 PM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1