Jump to content

Recommended Posts

Hi,

Please can someone help me with getting the "insertion point" of MS Word document after I use InsertAfter.  I have tried to reset _Word_DocRangeSet after InsertAfter but the insertion point of word continues to remain before the inserted text whereas I want it after the inserted text so I can continue typing after the inserted text.

Thanks for your help.

Regards,

Ajit

 

#include <Word.au3>

$oWord = _Word_Create()
$doc = _Word_DocAdd($oWord)
$oRange = _Word_DocRangeSet($doc, 0)
$oRange.Insertafter("INSERTED TEXT")

 

Edited by ajit
Link to comment
Share on other sites

Will check tomorrow.

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,

Thanks.

Regards,

Ajit

 

Edit:  When I used _Word_DocRangeSet from your UDF (WordEx.au3) it worked.  For some reason it does not work with the AutoIT include Word.au3.  Thanks.

Edited by ajit
Link to comment
Share on other sites

Which version of AutoIt do you run?

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

If you always want to add at the end of the document you could use:

#include <Word.au3>

$oWord = _Word_Create()
$oDoc = _Word_DocAdd($oWord)
$oRange = _Word_DocRangeSet($oDoc, 0)
$oRange.Insertafter("INSERTED TEXT")
$oRange = _Word_DocRangeSet($oDoc, -2)
$oRange.Insertafter(" INSERTED TEXT2")

 

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

InsertAfter extends the specified Range. To move the start of the new range to the end of the current range you could use the following Statements:

#include <Word.au3>

$oWord = _Word_Create()
$oDoc = _Word_DocAdd($oWord)
$oRange = _Word_DocRangeSet($oDoc, 0)
$oRange.Insertafter("INSERTED TEXT")
$oRange =  _Word_DocRangeSet($oDoc, $oRange, $WdCollapseEnd)
$oRange.Insertafter(" INSERTED TEXT2")

 

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,

Thanks for your reply.

Still the script is not working properly, not sure if Word version matters here.  I use MS Word 2003.

However, when I use function _Word_DocRangeSet from your WordEX.au3 it works fine and the insertion point moves to after "InsertAfter".

#include <Word.au3>

$oWord = _Word_Create()
$oDoc = _Word_DocAdd($oWord)
$oRange = _Word_DocRangeSet($oDoc, 0)
$oRange.Insertafter("INSERTED TEXT")
$oRange =  _Word_DocRangeSet_($oDoc, $oRange, Default, 2)



Func _Word_DocRangeSet_($oDoc, $oRange, $iStartUnit = Default, $iStartCount = Default, $iEndUnit = Default, $iEndCount = Default, $bSelect = Default)

    If $iStartUnit = Default Then $iStartUnit = $wdWord
    If $iEndUnit = Default Then $iEndUnit = $wdWord
    If $bSelect = Default Then $bSelect = True
    If Not IsObj($oDoc) Then Return SetError(1, 0, 0)
    If Not IsObj($oRange) And ($oRange < -2 Or $oRange > 0) Then Return SetError(2, 0, 0)
    If $oRange = -1 Then
        $oRange = $oDoc.Range ; Set range start/end at the start to the document
        $oRange.Collapse($wdCollapseStart)
    ElseIf $oRange = -2 Then
        $oRange = $oDoc.Range ; Set range start/end at the end to the document
        $oRange.Collapse($wdCollapseEnd)
    ElseIf $oRange = 0 Then
        $oRange = $oDoc.Parent.Selection.Range ; Use the current selection as range
    EndIf
    If $iStartUnit = -1 Then
        $oRange.Collapse($wdCollapseStart)
    ElseIf $iStartCount <> Default Then
        $oRange.MoveStart($iStartUnit, $iStartCount)
    EndIf
    If $iEndUnit = -1 Then
        $oRange.Collapse($wdCollapseEnd)
    ElseIf $iEndCount <> Default Then
        $oRange.MoveEnd($iEndUnit, $iEndCount)
    EndIf
    If $bSelect Then $oRange.Select ; Show the new range
    Return $oRange

EndFunc   ;==>_Word_DocRangeSet

Regards,

Ajit

Link to comment
Share on other sites

You mean

$oRange =  _Word_DocRangeSet($oDoc, $oRange, Default, 2) ; Move the start of the range two words to the right

of the Word UDF does not move the insertion mark to the right of the range?
I do not have Word 2003 available here so can't test. Already running Office 2016.

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,

That's right.   _Word_DocRangeSet of Word UDF does not move the insertion mark to the right of the range.  Problem could be because I am running an outdated version of Office. 

Thanks,

Ajit

 

 

 

 

Edited by ajit
Link to comment
Share on other sites

That's very strange. As it works with Word 2010 and Word 2016 I too think it is caused by the outdated version of Word :(

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...