If I copy something into the clipboard then use var=Paste[]; I get Null in the var and the clipboard content is printed on the next cell. How do I get the content of the clipboard directly into the variable.

I have a basic text in my clipboard and want it stored as a string.

Moreover Windows 10's clipboard now supports multiple entries. Is there a way to select entries other than the last one?


3 Answers 3


To get the last entry in clipboard you can use:

var = ToExpression[NotebookGet[ClipboardNotebook[]][[1, 1, 1, 1]]]

This works in version 9 / windows 10 (64bit).

  • $\begingroup$ This allows to get only the last entry from the clipboard on Windows 10. $\endgroup$ Commented Oct 24, 2021 at 4:04
  • $\begingroup$ Good point, thank you @AlexeyPopkov. $\endgroup$
    – kglr
    Commented Oct 24, 2021 at 19:33

This is perhaps a partial answer; it shows that using ctrl+v rather than Paste[] allows an expression to be assigned to a variable as required.

As an example, enter


Shows red box.

Select the box then use Paste from the context menu to copy it to the clip-board; then enter

x = Paste[]
x // FullForm

This shows x = Null.

Next, enter


then type ctrl+v

This gives the red box as expected; enter

y // FullForm

This gives RGBColor[1,0,0], which shows that the expressions has been passed to y as required.


Actually, there is an undocumented function for this purpose:PastContent[]

  • $\begingroup$ There is no built-in function PastContent, at least in version 12.3.1: Names["*`*Past*Content*"] returns empty list. Probably you refer to this: mmaqa.com/qa/1731/mmaexcelmma?show=1773#a1773 $\endgroup$ Commented Oct 24, 2021 at 3:59
  • $\begingroup$ @AlexeyPopkov Aha..Life is hard, and I don't remember what I ever did at all. That link you quoted is exactly one of the questions I answered myself a few years ago. BTW, you're Chinese? How did you find out about that community? $\endgroup$
    – yode
    Commented Oct 24, 2021 at 11:37
  • $\begingroup$ No, I've found this link here. $\endgroup$ Commented Oct 24, 2021 at 14:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.