Jump to content
xcaliber13

Help with the Word_DocRangeSet

Recommended Posts

xcaliber13

I have searched the help files and Internet.

Can the Word_DocRangeSet  be used to select range by page?

Here is what I want to do   Search a word doc for a string.  Once that string is found set the range to current page plus the next two pages.  Print that range. Loop thru doc.

Am I looking at the correct function DocRangeSet to do this?

Share this post


Link to post
Share on other sites
water

_Word_DocFind returns the range of the found search string. _Word_DocRangeSet seems to be the wrong function. I can't test at the moment but I think it should be something like this (incomplete):

Global $wdGoToBookmark = -1 ; A bookmark
Global $oRange = _Word_DocFind(...)
$oRange = $oDoc.Bookmarks("\page").Range ; Range of the current page

As soon as I'm at my Windows computer again I hope to come up with a solution.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
xcaliber13

Thank you Water.   Will wait for your help

Share this post


Link to post
Share on other sites
water

I'm sorry but with the limited amount of available spare time I could not find a way so select more then just the current page where the search item has been found:

#include <Word.au3>
$oWord = _Word_Create()
$oDoc = _Word_DocOpen($oWord, "C:\temp\Test_Word.docx")
$oRange = _Word_DocFind($oDoc, "takimatas") ; Search for a single word
$oRange.Select() ; Select the found word
$oRange = $oDoc.Bookmarks("\page").Range ; Expand the range to the full page
$oRange.Select() ; Select the full page

 


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
xcaliber13

Hey All,

          I got the script to select the page I am searching for and then print that page and the next 2 pages.   But it stops at the first occurrence of the search string. How to I make this script search for all occurrences of the search string?

#include <Word.au3>
#include <Date.au3>
Global Const $wdActiveEndPageNumber = 0x3
Local $oWord = _Word_Create()
$Date = StringFormat("%02u%02u", @MON, @MDAY) & StringRight(@Year, 2)
$oDoc = _Word_DocOpen($oWord, "Path to file")
$oRange = _Word_DocFind($oDoc, "93306") ; Search for a single word
$oRange.Select() ; Select the found word
$oRange = $oDoc.Bookmarks("\page").Range ; Expand the range to the full page
$oRange.Select()  ; Select the full page
$pg = $oDoc.Application.Selection.Information($wdActiveEndPageNumber)
;MsgBox($MB_SYSTEMMODAL, "", $pg & "-" &  $pg + 2)
_Word_DocPrint($oDoc, Default, Default, Default, Default, Default, $wdPrintRangeOfPages, Default, Default, $pg & "-" &  $pg + 2)

Any help pointing me in the right direction would be great

Share this post


Link to post
Share on other sites
water

Example 2 in the help file for _Word_DocFind should give you an idea.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
xcaliber13

Water,

           I have it going thru the whole document and printing the correct pages except that it does not find/print the very first occurrence of the DocFind.  Can you see what I am doing wrong?

#include <Word.au3>
#include <Date.au3>
Global Const $wdActiveEndPageNumber = 0x3

Local $oWord = _Word_Create()
Local $oDoc = _Word_DocOpen($oWord, "Path to doc file")
Local $oRange, $oSearch
$oSearchRange = _Word_DocRangeSet($oDoc, -1, $WdItem, 0)
$oRangeFound = _Word_DocFind($oDoc, "Text to Search", $oSearchRange) ;Default, Default) ; Search for a single word
While 1
   $oRange = _Word_DocFind($oDoc, "93306", $oSearchRange, $oRangeFound)
   $oRange.Select() ; Select the found word
   $oRange = $oDoc.Bookmarks("\page").Range ; Expand the range to the full page
   $oRange.Select()  ; Select the full page
   $pg = $oDoc.Application.Selection.Information($wdActiveEndPageNumber)
   _Word_DocPrint($oDoc, Default, Default, Default, Default, Default, $wdPrintRangeOfPages, Default, Default, $pg & "-" &  $pg + 2)
WEnd

Thank  you

Share this post


Link to post
Share on other sites
water

_Word_DocFind outside the While loop returns the first occurrence.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
ajit
On 02/02/2016 at 6:57 PM, water said:

 

@Water,

I am trying to use your code to split a word document using delimiters.

 

include <Word.au3>
$oWord = _Word_Create()
$oDoc = _Word_DocOpen($oWord, "C:\temp\Test_Word.docx")
$oRange = _Word_DocFind($oDoc, "takimatas") ; Search for a single word
$oRange.Select() ; Select the found word
$oRange = $oDoc.Bookmarks("\page").Range ; Expand the range to the full page
$oRange.Select() ; Select the full page

Second last line expands the range to the full page.  Instead of full page, I want it to expand the range to the next occurrence of "takimatas".  Is that possible? Actually would it be possible to have a collection of parts of the document in between delimiters? What I needed was to split the single document and create multiple documents separated by delimiters.  I need help specifically with expanding the range to next occurrence of "takimatas" and thus get a collection of ranges to paste in new individual documents.  

Thanks for any help you can provide.

Regards,

Ajit

 

Edited by ajit

Share this post


Link to post
Share on other sites
water

I would search for the second occurrance of "takimatas" and use the returned range to expand the "split range".


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
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

×