How to replace content between specific headers in Word document without changing format

I am working on Word automation and need guidance on updating content between specific headers without affecting the existing format.

Requirement Details:

  1. The bot reads a Word document.
  • The document contains multiple headers (topics).
  • Under each header, there are multiple bullet points.
  1. The bot needs to remove the content between two specific headers.
  • Example:
    Topic1
    (existing bullet point data)*
    Topic2
  • The bot should clear only the data between Topic1 and Topic2, not the headers.
  1. I have already extracted new data from the web.
  • The bot needs to insert this new data as bullet points between Topic1 and Topic2.
  1. Important constraint:
  • The existing Word formatting must remain unchanged (header style, bullet style, font, spacing, etc.).

Can someone please guide me on how to automate the below task using ?

Thanks in advance.

Hi @Ashokan_Shankar1

  • Use Word Application Scope.
  • Use Find or Find Text Position to locate the start of Topic1 and Topic2.
  • Get the Range between the end of Topic1 and start of Topic2.
  • Use Delete Range or Replace Text (with empty string) only for that range, not the headers.
  • Then use Insert Text at that same range and enable “Keep Source Formatting” or insert line by line as bullet points.

@Ashokan_Shankar1

Depending on how much data to be replaced you can try the approach

  1. Use replace text - First use read text and find the data you need then from that use replace to remove the data and at the same time to add new data by using the previous data as place holder
  2. Use word macros - this might not be straight way as it would need you to use .net or vba to edit data (but more clean way)

There are few limitations with first one - it can replace max 256 characters, also if number of bullet points donot match then it might be difficult as you cannot remove extra bullets, but at the same time only for clean up can use macro

cheers

Tables work quite nicely in word, just input a table below your Header topics with no visable borders, also the tale can be preformatted and once text is entered it will be whatever Font/Size is already set. Just loop to change table row dependant on amount of bullet points