Jump to content

word: replace text produces style mismatch


Recommended Posts

I want to make a listed text into a single paragraph, but the replace of text fails with styles...
I have this code:

$oRangeFound = _Word_DocFind($oDoc, "Nutrition:" , 0, $oSearchRange, Default, Default, $wdParagraph)
$oRangeFound = _Word_DocRangeSet($oDoc, $oRangeFound, $WdWord, 1, $wdParagraph, 1) 
$oRangeFound = _Word_DocRangeSet($oDoc, $oRangeFound, Default, 1, $wdCharacter, -1) 

if $arrangeNutrition then
  local $oRange1 = $oDoc.Range($oRangeFound.Start, $oRangeFound.End)
  $oRange1 = _Word_DocFindEX($oDoc, Default, Default, $oRange1, Default, Default, Default, Default, Default, Default, "Heading 2")
  $oRange1 = _Word_DocRangeSet($oDoc, $oRange1, Default, Default, $wdParagraph, -1)
  $oRangeFound.End = $oRange1.Start
endif

$resultTextNutrition = Stringreplace($oRangeFound.Text, @cr , " | ")

Consolewrite( "###" & $resultTextNutrition & @crlf)


$oRangeFound.Text = $resultTextNutrition & @crlf

From this:

image.png.0f5c5c67340b0257ee8a0e2a6f7f4acb.png

 

 I want this (Nutrition style Normal with "Nutrition:" remains bold, and the rest of the text all in Normal without bold):

image.png.aca6e4fecbb4960455199cea6faee29e.png

instead it becomes like ("Nutrition:" Heading 2, so it becomes part of the numbered list and New Title becomes 2 ...😞

image.png.9337b588f06643ba28e78e0384210713.png

testMe.docx

Edited by frank10
Link to post
Share on other sites
  • frank10 changed the title to word: replace text produces style mismatch

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...