The echo area is not really a buffer. It is an area of a window. It is used to display messages and to display the minibuffer (which is a buffer).
You cannot "visit" the echo area and select text there, as you would a buffer.
You or your code needs instead to visit buffer
*Messages*, where messages are logged. (Not everything displayed in the echo area gets logged there, however.)
This is what
C-h e does, for reference:
(defun view-echo-area-messages ()
"View the log of recent echo-area messages: the `*Messages*' buffer.
The number of messages retained in that buffer
is specified by the variable `message-log-max'."
From that you can see that you want to visit the buffer that is returned by evaluating
(messages-buffer) - this is generally buffer
You want a command something like this (e.g., bind it to a key):
(defun visit-*Messages* ()
"Visit buffer `*Messages*."
That will put you in the buffer at its end. But you still need to select the text you want, use
M-w, and then use
C-x 0 to hide the buffer.
If you know the beginning and end positions of the text you want to copy then you can do everything you want in the function. But those need to be positions in buffer
*Messages*. In that case, something like this:
(defun copy-from-*Messages* (start end &optional msgp)
"Copy text from BEG to END in buffer `*Messages* to kill ring."
(interactive (list (read-number "Start: ") (read-number "End: ") t))
(copy-region-as-kill start end))
(when msgp (message "Copied: %S" (car kill-ring)))
It's unlikely, I think, that you would want to invoke this interactively, as you won't know what the start and end positions are. But you might want to invoke it from Lisp code that knows the positions you're interested in.