Copy ONLY selected text to the windows clipboard

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ACF
    New Member
    • Jun 2007
    • 5

    Copy ONLY selected text to the windows clipboard

    Hello,
    I'm programming an application in MS Access 2003 / 2007 and would like to know how I can copy highlighted text to the windows clipboard?

    I am now using a statement in combination with module "Call ClipBoard_SetDa ta(Memo)" but this copies the whole 'memo' field.
    I want to highlight text in the memo field and copy only that text to the clipboard.

    What I really want is the VBA code for window's [Ctrl C] to copy selected text to the clipboard. I now use Ctrl C and then use a command to paste that text somewhere else and assign a category to it.

    I want to make these 2 steps just 1. So in effect the code that runs behind the [Ctrl C] command in windows. I'll paste that in the VBA code and the user has to apply only one keystroke (or click).

    Greetings,
    ACF
  • ADezii
    Recognized Expert Expert
    • Apr 2006
    • 8834

    #2
    Originally posted by ACF
    Hello,
    I'm programming an application in MS Access 2003 / 2007 and would like to know how I can copy highlighted text to the windows clipboard?

    I am now using a statement in combination with module "Call ClipBoard_SetDa ta(Memo)" but this copies the whole 'memo' field.
    I want to highlight text in the memo field and copy only that text to the clipboard.

    What I really want is the VBA code for window's [Ctrl C] to copy selected text to the clipboard. I now use Ctrl C and then use a command to paste that text somewhere else and assign a category to it.

    I want to make these 2 steps just 1. So in effect the code that runs behind the [Ctrl C] command in windows. I'll paste that in the VBA code and the user has to apply only one keystroke (or click).

    Greetings,
    ACF
    The following code will:

    1. Set Focus to the [LastName] Field.
    2. Select the entire Field's contents.
    3. Copy the entry in this Field to the Windows Clipboard.
    4. Is this what you are looking for?

    [CODE=vb]Me![LastName].SetFocus
    Me![LastName].SelStart = 0
    Me![LastName].SelLength = Len(Me![LastName])
    SendKeys "^c"[/CODE]

    Comment

    • ACF
      New Member
      • Jun 2007
      • 5

      #3
      Thanks for your feedback, although code is for VB (will that work for VBA)?

      But this will copy still the whole field


      [CODE=vb]
      Me![LastName].SetFocus
      Me![LastName].SelStart = 0
      Me![LastName].SelLength = Len(Me![LastName])
      SendKeys "^c"
      [/CODE]

      I want the SelStart at the start of the text I've highlighted and SelLenght the number of characters I've highlighted (selected).

      Is that possible?

      Comment

      • FishVal
        Recognized Expert Specialist
        • Jun 2007
        • 2656

        #4
        Originally posted by ACF
        Thanks for your feedback, although code is for VB (will that work for VBA)?

        But this will copy still the whole field

        [CODE=vb]
        Me![LastName].SetFocus
        Me![LastName].SelStart = 0
        Me![LastName].SelLength = Len(Me![LastName])
        SendKeys "^c"
        [/CODE]

        I want the SelStart at the start of the text I've highlighted and SelLenght the number of characters I've highlighted (selected).

        Is that possible?
        Hi!

        As far as I've have got it you want to implement the following functionality.
        User selects a part of text in a textbox.
        Then the textbox looses focus and the selected part remains highlighted.
        Then something (e.g. button click) trigger copy of the selected text to clipboard.
        Reentering to the textbox clears the selection.

        Am I right? If so, I have a simple solution.

        Comment

        • ADezii
          Recognized Expert Expert
          • Apr 2006
          • 8834

          #5
          Originally posted by ACF
          Thanks for your feedback, although code is for VB (will that work for VBA)?

          But this will copy still the whole field

          [CODE=vb]
          Me![LastName].SetFocus
          Me![LastName].SelStart = 0
          Me![LastName].SelLength = Len(Me![LastName])
          SendKeys "^c"
          [/CODE]

          I want the SelStart at the start of the text I've highlighted and SelLenght the number of characters I've highlighted (selected).

          Is that possible?
          The code I gave you is generic and will work in VBA. Visual Basic (VB) has its own built-in Methods for moving Text and Graphics into and out of the Clipboard, namely: SetText and GetText for TEXT and SetData and GetData for GRAPHICS.

          Comment

          Working...