+ Reply to Thread
Results 1 to 3 of 3

Put in clipboard, but keep the current content

  1. #1
    Eric van Uden
    Guest

    Put in clipboard, but keep the current content

    Hello group,

    I have a userform to add or edit comments and progress reports regarding a
    project my team is working on.
    There is a button to insert the date (in square brackets) in the textbox
    where the cursor happens to be. There are 3 textboxes.

    I have this code that formats the date, puts it in the clipboard, and
    pastes it into the textbox:

    Dim Date1 As New DataObject
    Date1 .SetText "[" & Format(Date, "dd/mm/yy") & "] "
    Date1 .PutInClipboard
    Application.SendKeys ("^v")

    Howecer, by copying to the clipboard, I wipe whatever is there previously.
    In some cases this is very inconvenient.

    Is there a way to store the contents of the clipboard somewhere, perform
    this action, and then put the previous contents back in the clipboard?
    My attempts to put some GetFromClipboard and PutInClipboard lines in series
    were unsuccessful. Only the first action seems to get through. Or the second
    gets put into a second clipboard instance, which I don't know how to
    address.
    Is there a way to address a specific clipboard instance, so that after
    pasting the date, i can still use Ctrl + V to paste whatever I copied
    earlier into the form?
    Or is there a way to reference the active textbox and enter the formatted
    date directly at the top left, without going via the clipboard?

    Any assistance would be appreciated.

    Eric



  2. #2
    Tom Ogilvy
    Guest

    Re: Put in clipboard, but keep the current content

    Userform1.Textbox1.Text = "[" & Format(Date, "dd/mm/yy") & "] "

    Might be what you want.

    or
    If typeof Userform1.ActiveControl is MSForms.Textbox then
    Userform1.Activecontrol.Text = "[" & Format(Date, "dd/mm/yy") & "] "
    End if

    --
    Regards,
    Tom Ogilvy

    "Eric van Uden" <ericvanuden THISGOES @ OUT supermail.nl> wrote in message
    news:[email protected]...
    > Hello group,
    >
    > I have a userform to add or edit comments and progress reports regarding a
    > project my team is working on.
    > There is a button to insert the date (in square brackets) in the textbox
    > where the cursor happens to be. There are 3 textboxes.
    >
    > I have this code that formats the date, puts it in the clipboard, and
    > pastes it into the textbox:
    >
    > Dim Date1 As New DataObject
    > Date1 .SetText "[" & Format(Date, "dd/mm/yy") & "] "
    > Date1 .PutInClipboard
    > Application.SendKeys ("^v")
    >
    > Howecer, by copying to the clipboard, I wipe whatever is there previously.
    > In some cases this is very inconvenient.
    >
    > Is there a way to store the contents of the clipboard somewhere, perform
    > this action, and then put the previous contents back in the clipboard?
    > My attempts to put some GetFromClipboard and PutInClipboard lines in

    series
    > were unsuccessful. Only the first action seems to get through. Or the

    second
    > gets put into a second clipboard instance, which I don't know how to
    > address.
    > Is there a way to address a specific clipboard instance, so that after
    > pasting the date, i can still use Ctrl + V to paste whatever I copied
    > earlier into the form?
    > Or is there a way to reference the active textbox and enter the formatted
    > date directly at the top left, without going via the clipboard?
    >
    > Any assistance would be appreciated.
    >
    > Eric
    >
    >




  3. #3
    Eric van Uden
    Guest

    Re: Put in clipboard, but keep the current content

    Hello Tom,

    Thnak you for your help.

    Your second suggestion pointed me to a way to (indirectly) find out which
    textbox has focus. Excel retuns as ActiveControl the frame in which I put
    each of the three textboxes, but ther is only one textbox in each frame. So:

    If Me.ActiveControl Is Remark1Frame Then Remark1Box.Text = date1
    If Me.ActiveControl Is Remark2Frame Then Remark2Box.Text = date1
    If Me.ActiveControl Is Remark3Frame Then Remark3Box.Text = date1

    This works fine. Only it replaces the entire textbox contents with the date1
    string.
    My previous cut'n'paste method allowed for insertion at the cursor's
    location.

    Is there a way to insert a string at the cursor position, now I've
    established which textbox it's in?



    "Tom Ogilvy" <[email protected]> schreef in bericht
    news:%[email protected]...
    > Userform1.Textbox1.Text = "[" & Format(Date, "dd/mm/yy") & "] "
    >
    > Might be what you want.
    >
    > or
    > If typeof Userform1.ActiveControl is MSForms.Textbox then
    > Userform1.Activecontrol.Text = "[" & Format(Date, "dd/mm/yy") & "] "
    > End if
    >
    > --
    > Regards,
    > Tom Ogilvy
    >
    > "Eric van Uden" <ericvanuden THISGOES @ OUT supermail.nl> wrote in message
    > news:[email protected]...
    >> Hello group,
    >>
    >> I have a userform to add or edit comments and progress reports regarding
    >> a
    >> project my team is working on.
    >> There is a button to insert the date (in square brackets) in the textbox
    >> where the cursor happens to be. There are 3 textboxes.
    >>
    >> I have this code that formats the date, puts it in the clipboard, and
    >> pastes it into the textbox:
    >>
    >> Dim Date1 As New DataObject
    >> Date1 .SetText "[" & Format(Date, "dd/mm/yy") & "] "
    >> Date1 .PutInClipboard
    >> Application.SendKeys ("^v")
    >>
    >> Howecer, by copying to the clipboard, I wipe whatever is there
    >> previously.
    >> In some cases this is very inconvenient.
    >>
    >> Is there a way to store the contents of the clipboard somewhere, perform
    >> this action, and then put the previous contents back in the clipboard?
    >> My attempts to put some GetFromClipboard and PutInClipboard lines in

    > series
    >> were unsuccessful. Only the first action seems to get through. Or the

    > second
    >> gets put into a second clipboard instance, which I don't know how to
    >> address.
    >> Is there a way to address a specific clipboard instance, so that after
    >> pasting the date, i can still use Ctrl + V to paste whatever I copied
    >> earlier into the form?
    >> Or is there a way to reference the active textbox and enter the formatted
    >> date directly at the top left, without going via the clipboard?
    >>
    >> Any assistance would be appreciated.
    >>
    >> Eric
    >>
    >>

    >
    >




+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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