Jump to content

Help with the Word_DocRangeSet


Recommended Posts

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?

Link to comment
Share on other sites

_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 (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

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 (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

  • 2 months later...

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

Link to comment
Share on other sites

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

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

_Word_DocFind outside the While loop returns the first occurrence.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

  • 3 months later...
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
Link to comment
Share on other sites

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 (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...