How to move selection based on word outline?

Hello everyone,
I am trying to write a script for adding TAGs as comment into word document. The idea is to add a tag for every heading and sub-heading present in document. The input word documents do not have 'word style' followed. I have following two questions.
1.) How can I extract number of headings based on outline? The document do not use word styles for adding headings or sub-headings. This makes it difficult to use 'outlineLevel' to be used. As if a heading is written in normal text then outlineLevel will
return '10' and script will miss this heading. I read on another forum that outlineNumber can be used but it does not seem to be working with paragraph object.
2.) How to move selection from one heading to next? Currently my script is not able to move selection.
Below is the script I manage to write. (I'm new to scripting and this is my 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 will need to get the selection range object and reference it as a range.  If the outline is not really an outline then how would you use it?  I think if you clarify your question it might lead you to seeing an answer.
If it is an outline you should be able to just walk the outline.  Any outline element can have a text (10) section attached. 
I would suggest that you start in the Word Developers forum and try to understand how this would be done in VBA or C# then translate it into PowerShell.
I would also recommend creating this as a callable macro or function in the word doc or a template. You can then just open and call the macro from PowerShell.
¯\_(ツ)_/¯

Similar Messages

  • How to dynamic select based on runtime value ?

    how to dynamic select based on runtime value ?
    I want to write a select function, which do selecting based on parameters. eg,
    CREATE OR REPLACE FUNCTION myfunction
    (tableName VARCHAR2, pkName VARCHAR2, pkValue VARCHAR2, requestString VARCHAR2)
    RETURN VARCHAR2 AS
    BEGIN
    select requestString from tableName where pkName=pkValue;
    RETURN NULL;
    END;
    myfunction('users', 'user_id', '100', 'user_name'); it will select 'user_name' from table 'users' where 'user_id' = '100'.
    This way could save lots of coding. but it can't pass compiler. how to work out ?
    Thanks.

    While this may save code, if used frequently it will be ineffecient as all [explicative deleted]. The danger is that it would be used even for repeatable statements.
    This mode of operation ensures that every statement [calling the funciton] needs to be reparsed, which is extremely expensive in Oracle (in CPU cycles, recursive SQL and shared pool memory).
    Such reparsing is rarely a good thing for the environment ... it could easily lead to buying more CPU (bigger box) and therefore adding more Oracle license ... which could quickly exceed the typical developer's salary.
    However - if you really, really want to do this, look up 'execute immendiate' in the PL/SQL manuals.

  • How to move selected photos to iCloud (I have 29Gb photos and 15Gb iCloud storage)?

    Hi
    I have 29Gb photos and I can't back them all up in my 15Gb iCloud storage.
    How to move some of them to iCloud?
    Thanks in advance!

    Hello MagStock,
    Thanks for using Apple Support Communities.
    It is not possible to save photos to iCloud directly.
    iCloud: My Photo Stream FAQ
    http://support.apple.com/kb/ht4486
    Does using My Photo Stream substitute for using iCloud Backup or iTunes to back up the photos in my Camera Roll ?
    No. Photos in My Photo Stream are saved on the iCloud server for 30 days. To save or back up these photos, you must copy them from My Photo Stream to your Camera Roll on your iOS device. You can then back up your Camera Roll using iCloud or iTunes.
    iCloud: Photos overview
    http://support.apple.com/kb/PH2604
    iCloud also stores all your photos recently added to your devices in My Photo Stream.
    Have a nice day,
    Mario

  • How to move selected values in a table in one view to another

    Dear Experts,
    In my application,I have a table populated with data.My requirement is to select a row in the table and move the selected values of the row to the next view.
    Can anybody tell how to do this??
    Regards,
    Mamai.

    Hi mamai,
    First create a two internal tables ( nodes) itab1 & itab 2 with your required structure in component controller.
    Then bind the itab1 with view1 controller context.
    bind the itab2 with view2 controller context. and create a tables in both views and bind with itab1 and itab2 respectively.
    after getting the itab1 data, use the below code in wddoinit method of view2.
    data: count type i,
            pos type i value 1.
    Count = lo_nd_itab1->get_element_count( ).
    do count times.
    to copy the selected records
    if lo_nd_itab1->is_selected( index = pos ) = abap_true.
    lo_el_itab1 = lo_nd_itab1->get_element( index = pos ).
    lo_el_itab1->get_Static_attributes( importing static_attributes = ls_itab1 ).
    lo_el_itab2 = lo_nd_itab2->creat_element( ).
    lo_el_itab2->set_static_attributes( exporting static_attributes = ls_itab1 )
    lo_nd_itab2->bind_element( new-item = lo_el_itab2 set_initial_elements = abap_false ).
    endif.
    pos = pos + 1.
    enddo.
    Regards
    Srinivas

  • How do I select a specific word inside a TextFrame?

    I want to highlight a word inside a TextFrame, but I'm only able to select the entire frame.
    I have tried something (and several related version) like this:
    var textFrames:com.adobe.indesign.TextFrames = activeDocument.textFrames;
      for(var i:int = 0; i < textFrames.length; i++){
      var t:com.adobe.indesign.TextFrame = textFrames.item(i);
      var texts:com.adobe.indesign.Texts = t.texts;
        for(var j:int = 0; j < texts.length; j++){
          var text:com.adobe.indesign.Text = texts.item(j);
          app.select(text);
    This selects the entire content of the area, instead of just a specific word.
    How do I proceed? Thanks

    To clarify: I dont know which TextFrame the string is within - hence i look through all frames.
    I have tried implementing the suggested ideas - mainly doc.findText() as:
    app.findTextPreferences.findWhat = word;
    var w:Object = doc.findText();
    The problem is the findText() returns object of all types, and I cannot figure how to get it working. Below is my current solution, working like a charm, though probably not the most efficient implementation.
    public static function select(word:String):void{
      var app:Application = InDesign.app;
      var activeDocument:Document = app.activeDocument;
      if (!activeDocument){
      return;
      var textFrames:com.adobe.indesign.TextFrames = activeDocument.textFrames;
      for(var i:int = 0; i < textFrames.length; i++){
      var t:com.adobe.indesign.TextFrame = textFrames.item(i);
      var words:Words = t.words;
      for(var j:int = 0; j < words.length; j++){
      var selector:Word = words.item(j);
      if(selector.contents.toString() == word){
      selector.select();
      return;

  • Newest iMovie - how to move selected parts of clips from events to trash

    Hello,
    I have used to import clips to events and than trimmed them down with the function "reject selection" and than when I used "Move rejected clips to trash" or something like that, iMovie removed the selections from the clips and generated new clips ones. It was fast and very nice feature.
    Now, with the new version I can't seem to find this functionality? Am I missing something?
    Kind regards,
    Uros

    Got the same problem. The menu item has disappeared in this botched-up job of an iMovie upgrade. When I tried to select rejected clips/segments and move them to the trash I was told to wait until iMovie has finished running tasks and that I'm to check the activity indicator. Problem is, there're no running tasks and no activity indicator!

  • How do you select multiple / separate words in Pages?

    Hi, I currently have Pages 5.5 (2109)
    and the title is self-explanatory.
    I'm trying to shift over from Microsoft Word, but this one function seems not to be at present.
    Can somebody help me?
    If it does not exist, is there any way you can dictate it?
    Thank you,
    Henry

    Use Pages '09.
    Peter

  • How do I add a two word phrase to index

    I’m trying to speed up the process of adding Latin names of plants and animals to an index using Indesign CS4. These consist of two word phrases (genus + species) which need to be put into the topic level 1 and topic level 2 boxes of the New Page Reference (Index) dialog. Using Ctrl 7 to invoke the dialog just puts whatever is selected into Topic1 and using Shift+Ctrl+Alt+] adds a ‘proper name’ index entry (Surname, forename) which is no good. When the information has been entered, a simple nested index can be produced, sorted by  genus and then species.
    I’m used to programming using vb in MS Office but am totally new to javascript and this has taken two days to get this far. The first problem is that if the user only puts an insertion point into the first word (genus) I can’t figure out how to move to the second word (species) in order to save it to a variable.
    So I have:
    var myTopic1 = "" ; // topic level 1, i.e. genus
    var myTopic2 = "" ; // topic level 2, i.e. species
    myIP = app.selection[0] ;
    myTopic1 = myIP.words[0].contents ;
    This works on a insertion point in any word, or if a phrase is highlighted will take the first word.
    Is there a simple way of copying the second word after the insertion point to myTopic2? I’ve tried various methods but can’t get anything to work. I thought it would be a simple matter of adding 1 to the index of the containing paragraph or story.
    I’ve got round this in a very long-winded way by asking the user to select the whole genus+species string, then working out the position of the dividing space and reconstructing the genus and species character by character:
    var myString = "" ; // user-selected string: genus + species
    myString = myIP.contents
    myStringlen = myIP.contents.length
    var xposn = myString.indexOf(" "); // gives posn of the (first) space character within selected string
    var yposn = 0 ; // start of the string
    myTopic1 = myString.charAt(yposn) ;
    while (yposn < (xposn-1))
    myTopic1 = myTopic1 + myString.charAt(yposn+1) ;
    yposn++ ;
    while (xposn < myStringlen)
    myTopic2 = myTopic2 + myString.charAt(xposn+1) ;
    xposn++ ;
    // show results:
    alert("Topic1 = " + myTopic1 + ". Topic 2 = " +myTopic2) ;
    So at this point I need to figure how to invoke the New Page Reference dialog with Topic1 and Topic 2 filled in? I would like the option of overriding the character format of the page reference ‘Number Style Override’, so would prefer to conclude the script with the dialog left open. Can this be done using script, or do I need a custom dialog? Alternatively it would also be good to just automatically save Topic1 and Topic2 and insert the index marker at the selection point without invoking any dialogs. I’m really struggling to get anywhere with this, can someone please help! Many thanks. Sorry for the long post.

    John,
    It can be confusing initially, but JavaScript and InDesign's object model will soon make sense. What you want to do can be done with this script:
    w1 = app.selection[0].words[0].contents;
    w2 = app.selection[0].words[1].contents;
    doc = app.activeDocument;
    if (doc.indexes.length == 0){
        doc.indexes.add();
    species = doc.indexes[0].topics.add (w1).topics.add (w2);
    species.pageReferences.add (app.selection[0], PageReferenceType.currentPage);
    Select genus and species, then run the script.
    It's not possible (I don't think) to open the New page Reference dialog. Do you want to apply the number style override to all page references? If that's the case, don't. Apply the character style to the page numbers after the index has been generated, or better, set it in the index paragraph style.
    If you want to apply the number style override only to some pages, you can do as follows. Before selecting genus+species, prefix the genus name with e.g. #. That symbol tells the script to add an override. The script will strip the #, create the page reference, and add the override. You need to tell the script somehow which character style to use for the override.
    Peter
    Edit: Jump beat me to it, and gives you a different method to get your two words. Spoilt for choice!
    P.

  • How to move over text in a sub-menu --

    Hi - I hope someone can help me because I'm stumped.  In my previous post:
    https://forums.adobe.com/thread/1669049?sr=stream
    ...the forum team helped me figure out how to fix bullets in a list.  But now someone else brought it to my attention and I tried to fix it but cannot figure it out.  Now the sub-menu words are way too close to the left edge of the main navigation:
    So I'm not sure what to do to leave the bullet lists, which work great, alone but how to fix those sub-menu words to move them over to the right away from the left edge.  Here's the main CSS file and the change I made from the previous post starts at line 432:
    https://dev3.orr.noaa.gov/sites/all/themes/creative-responsive-theme/style.css
    Any ideas?  Any help is greatly appreciated and thanks.

    Hi Ken,
    The reason why the -11 is there is because in a previous post:
    Bullets in list aren't displaying - can't figure out why
    I added it to fix the bullet lists so that the text wraps and the bullet lists line up like they should.  When I added it, though, it's now affecting the navigation.
    UPDATE - I was able to pinpoint the exact code that affects the sub-menu text.  The code is the CSS file is:
    #main-menu li li a {
      color: #C5C5C5;
      min-width: 150px;
      margin: 0;
      background: #1e272e;
      border-top: 1px solid #333;
      font-size: 11px;
      text-align: left;
      overflow: hidden;
      padding: 3% 5%;
      font-weight: normal;
    The way I confirmed that the above code is what I need to fix is I changed the font size to 16, just to see what would happen and here is the result I got:
    So that above code seems to be the code that will affect the layout of the sub-menu words that I'm trying to move over a little bit from the left margin.  Then I tried to tweak the margin and padding.  I first added 10px to the left margin like this (margin: 0 0 0 10px) and that did not work.  I then tried to add 1% to the padding and that did not work either.  So I'm really stumped about how to move those sub-menu words over from the left a little bit.  Any ideas?

  • How to move a selection into another selection in elements 12

    how to move a selection into another selection in elements 12

    Open picture B, the one you wish to select something from to add to another picture.
    Use one of the selection tools, e.g. selection brush, lasso tool, to select the object. You will see an outline ("marching ants") once the selection is complete
    Go to Edit menu>copy to copy the selection to the clipboard
    Open picture A, then go to Edit>paste
    Use the move tool to position object from picture B.
    In the layers palette you should see picture A as the background layer, and object B on a separate layer

  • How can I select and enlarge the entire doc,ge on a page, reducing the surrounding boarder.  I can move the difference text boxes about independently of each other but the outer most boarders of the main template block appear to be fixed.

    How can I select adn enlarge the entire document/image on a page, reducing the the surrounding boarder?  I can move the different text and image boxes around independently of each other but the outer most boarders of the main template block appear to be fixed.  I thought I would be able to enlarge or reduce my document from 'page layout' but this does not seem possible.

    Inspector > Document > Document Margins
    The word is border. Boarders are the Harry Potters of this world.
    Peter

  • How to move pictures from iphoto to word

    how to move pictures from iphoto to word

    how to move pictures from iphoto to word
    Word cannot store pictures - do you mean, how to use the photos in your iPhoto Library in Word documents?
    Use the Media Browser in Word - when you select to insert a photo, you can open the Media Browser like this and browse your photo libraries - iPhoto, Aperture, ...
    Sorry, my office applications have a german language interface, but the icons should be the same.
    Regards
    Léonie

  • Using 12.0.1.26 Im trying to move photo's from an app on the pad to laptop but the select all in Edit is not hilighted, how to you select all?

    the select all under edit is not highlighted in 12.0.1.26, I need to move a large number of photos from pad app sharing area to laptop, how do I select all? Thanks

    the select all under edit is not highlighted in 12.0.1.26, I need to move a large number of photos from pad app sharing area to laptop, how do I select all? Thanks

  • How do you select and move more than one bookmark at a time? Shift+Click does not select multiple items that are next to one another in a list because the item

    How do you select and move more than one bookmark at a time?
    Shift+Click does not select multiple items that are next to one another in a list because the items open in firefox before this happens.

    Use the bookmarks library. You may use Shift +Click, and Ctrl + Click to create groupings of selected bookmarks to drag and drop.
    * one method of opening the bookmarks library is keyboard shortcut <br /> Ctrl+Shift+B (Windows)
    *see also [[How to use bookmarks to save and organize your favorite websites]]
    *and [[Use bookmark folders to organize your bookmarks]]

  • How do I select more than one frame? (editing a movie in PS)

    Fisrt time ive tried this.
    I want to do a quick selecton on a movie clip but can only seem to select 1 fram at a time. How can I select more than one frame?
    cheers
    jamie

    If you used Sequence to Layers, Shift and Control key in the layers palette work just as they would when selecting files in Explorer... If it's a video layer, then you should only see one layer and will have to use the Timeline to navigate.
    Mylenium

Maybe you are looking for

  • T430s - Unable to install Windows 8.1 update / Requires Rapidboot to be uninstalled

    Hi folks, I'm trying to install the Windows 8.1 update on my Windows 8 Pro but I'm in front of an issue. After doing the check to perform the update, it does ask me to uninstall RapidBoot in order to perform the update. I've checked in my programs to

  • Can't back up iPhone 5 to my computer

    Can't back up my iPhone 5 to my computer using iTunes. The "back up now" or "Restore" bottons are grey

  • Is splitting Model-UI a must in InDesign CS5?

    Hello, According to the CS5 porting guide and the Programming Guide, it is now mandatory to split the plugin into UI and Model. UI plugin should not have commands, responders, persistent classes, event handlers or service providers. However, one of m

  • Is it a way to read Multiple Attachment and send all     - Mail Sender?

    Hi Friends ,                       Can you please tell me how to send multiple Attachment in Mail Sender Adapter  ?                  <b>      I am able to bring Multiple Attachement in Payload .But, Only one attachemen't data is passed to IS.</b>    

  • Type not printing

    I am using Classic paperback book-medium size--no black background. I have four lines of type to a page but some lines do not print. I made a PDF and this confirms the type does not show up. Also printed out the book and the same type is missing. It