ahha

[Solved] _Word_DocRangeSet seems intermittent

6 posts in this topic

#1 ·  Posted (edited)

Okay I've hacked down a large program to illustrate the problem I'm having.

I'm using the built-in Word UDF (which is great) and am finding a range and then copying it to the clipboard and sticking it in an array for viewing.

Then extending the range and again copying it to a clipboard and sticking it into the array.

It seems to drop the ranges randomly.  I can't figure out what I'm doing wrong (or if there's a better way to get a range into a variable).

Run the program with the test file and you'll see entries being dropped (put test file in same directory as the program).

Any pointers or help much appreciated.

Hacked down program for testing Range extend and copy v3c.au3

Test for Range Copy v1a.docx

Edited by ahha
solved

Share this post


Link to post
Share on other sites



#2 ·  Posted

Why do you use the Clipboard? Couldn't you just copy the text to the array?
I would replace

$oRangeFound.Copy   ;v3c copy to clipboard
    $clip = ClipGet()
    $aFilenames[$count][0] = $clip

with

$aFilenames[$count][0] = $oRangeFound.Text

 


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#3 ·  Posted

water,

Thank you.  :)

Using .Text seems to work fine.  It looks like either .Copy and/or ClipGet() are the intermittent culprits.

BTW - is there a list somewhere of the dot operations like .Text ?  I'm still learning (always).

Share this post


Link to post
Share on other sites

#4 ·  Posted


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#5 ·  Posted

Thanks.  BTW I've forgotten how to mark the title as [Solved]

Share this post


Link to post
Share on other sites

#6 ·  Posted

Edit the first post in this thread and edit the title.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

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

  • Similar Content

    • ahha
      By ahha
      Okay this is likely due to my not properly understanding objects.
      I'm using _Word_DocRangeSet to extend a range (in this case to the end of a line).
      The issue I've encountered is that extending one range seems to affect another range.
      It may be that an object can't be assigned or equated.
      In any event the program and test file (place in the same directory) illustrate the issue.
      Test 1 - shows the documentation for _Word_DocRangeSet correctly shows how the range is extended and the assigned result is extended.  No problem here just part of my learning.
      Test 2 - like Test 1 but no assignment of the result from  _Word_DocRangeSet is needed.  Again correct and my learning.
      Test 3 - here is where the issue is.  After an assignment to a new object the old one seems to be affected by _Word_DocRangeSet.  This I don't understand (perhaps the assignment is really a namespace pool and points to the same structure like aliases <-- wild guess).
      Test 4 - shows that using .Select can extend the range and leave the original range alone.
      Any hints/pointers on what's going on appreciated.
      Thanks
      WordRangeTesting v1c.au3
      Test for WordRangeTesting v1c.docx
    • Lights_On
      By Lights_On
      Hi all,
      The below string works if the searched term exists, however if it does not - I don't get an '@error' or '@extended' - the scrip appears to just keep running?
      Local $result = _Word_DocFind($oDoc, $ComString, 0, Default, True, False, True, True) I can get errors with other combination of parameters but not with the above however only the above does what i need.  It seems to be the combination of: 
      $bMatchWildcards  
      $bMatchWholeWord that is does not like if a term can not be matched, as changing one of these allows for an error to be found but then also no matches are found.
       
      I seek to create an 'if' statement using the above string so when it finds a match is does one set of things, and if no match is found then it does something else.  With out an error being generated i can only do something when a match is found and when a match is not found the script just hangs as does not set and error so as such does not move on?
       
      Scratching my head on this one.
       
      Thank you in advance. 
      V3.3.14.2
    • Servant
      By Servant
      I tried a lot of techniques but still have no luck..
      How can I delete the second sentence until the last sentence of a set paragraph range on a Microsoft Word document?
      #include <Word.au3> Global $oWord, $oDoc $oWord = _Word_Create() $oDoc = _Word_DocGet($oWord, 1) Global Const $Count = $oDoc.Paragraphs.Count For $i = 0 To $Count - 1    $oRange = _Word_DocRangeSet($oDoc, -1, $wdParagraph, $i, $wdParagraph, 1)    ; Here will be placed the missing code Next Sample of the beginning of a Word document:
      This is a sentence 1. This is a sentence 2. This is a sentence 3. This is a sentence 4. This is a sentence 5. This is a sentence 6. This is a sentence 7. This is a sentence 8. This is a sentence 9. Sample of the final result:
      This is a sentence 1. This is a sentence 4. This is a sentence 7.
    • Servant
      By Servant
      Is there a way to get the style of a set range on a Microsoft Word document?
      If there is, then how?