Reputation: 11
Inside a google doc document, I regularly have to copy-paste whole paragraphs in various places.
Is there a way to copy my paragraph so that it replicates at places defined in the google doc?
With the macros function on google sheet, I can do it very well but I need to work in a doc environment.
Upvotes: 0
Views: 79
Reputation: 15377
You can use the replaceText()
method of the Body
class to replace text in a document programmatically.
function replaceText(){
const pText = "This is a long paragraph that I have to insert into my\
document a load of times so instead of copying and pasting it each\
time I need to use it, I will simply use the built-in replaceText()\
method - it will replace all instances of the string {{paragraph}}.";
var docBody = DocumentApp.getActiveDocument().getBody();
docBody.replaceText('{{paragraph}}', pText);
}
Upvotes: 1