How to move selection based on word outline?


hello everyone,

i trying write script adding tags comment word document. idea add tag every heading , sub-heading present in document. input word documents not have 'word style' followed. have following 2 questions.

1.) how can extract number of headings based on outline? document not use word styles adding headings or sub-headings. makes difficult use 'outlinelevel' used. if heading written in normal text outlinelevel return '10' , script miss heading. read on forum outlinenumber can used not seem working paragraph object.

2.) how move selection 1 heading next? script not able move selection.

below script manage write. (i'm new scripting , first script)

$filepath = "h:\desktop\ashishk\f1k\functionalsafetycopy.docx"  $word = new-object -comobject word.application  $word.visible = $false $mindepth = 1 $maxdepth = 9 $tagprefix = "ts_fs_" $tagstart = 1 $tagstep = 1 $tagnew = 0 #document object $doc = $word.documents.open($filepath)   $section = $doc.sections.item(1) $range = $section.range $outline = $doc.paragraphs | foreach-object {    if($_.outlinelevel -le $maxdepth){       write-host "outlinelevel:" $_.outlinelevel      if($tagnew -eq 0){           $_.comments.add($range, "$tagprefix$tagstart")           $tagnew = $tagstart + $tagstep           write-host "new tag number:" $tagnew      }      else{          $doc.comments.add($range, "$tagprefix$tagnew")         $tagnew = $tagnew + $tagstep         write-host "new tag number:" $tagnew      }    } } $doc.save()  $doc.close()  $word.quit()


you need the selection range object , reference range.  if outline not outline how use it?  think if clarify question might lead seeing answer.

if outline should able walk outline.  outline element can have text (10) section attached. 

i suggest start in word developers forum , try understand how done in vba or c# translate powershell.

i recommend creating callable macro or function in word doc or template. can open , call macro powershell.


¯\_(ツ)_/¯



Windows Server  >  Windows PowerShell



Comments

Popular posts from this blog

WIMMount (HSM) causing cluster storage to go redirected (2012r2 DC)

Failed to delete the test record dcdiag-test-record in zone test.com

Azure MFA with Azure AD and RDS