Macro : button to copy a cell value to the window clipboard memory

Hello,

Simple question.
On my active sheet, I want to make a button with macro that copy a specific cell to the window clipboard (=like if I was doing ctrl+c).

Can someone give me the function to achieve this ?

So I will just have to click on the button and do ctrl+v to paste the content to another app.

Thanks

Hello @Qrs
Probably there’s the way. Please check out this macro sample:

var oWorksheet = Api.GetActiveSheet();
var sValue = oWorksheet.GetRange("A1").GetValue();
console.log(sValue)

navigator.clipboard.writeText(sValue)
  .then(() => {
    // Done!
  })
  .catch(err => {
    console.log('Something went wrong', err);
  });

Hi thank you very much, your code give me an error because of brackets missing on the second part : .catch(err…

But it works just correctly with this :

(function()
{
var oWorksheet = Api.GetActiveSheet();
var sValue = oWorksheet.GetRange(“E3”).GetValue();
console.log(sValue);

navigator.clipboard.writeText(sValue)
.then(() => {
// Done!
});

})();
1 Like

We are glad to have helped.