ajit

Word InsertAfter

11 posts in this topic

#1 ·  Posted (edited)

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

Share this post


Link to post
Share on other sites



#2 ·  Posted

Will check tomorrow.


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 (edited)

@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

Share this post


Link to post
Share on other sites

#4 ·  Posted

Which version of AutoIt do you run?


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

Production version 3.3.14.2

Regards,

Ajit

Share this post


Link to post
Share on other sites

#6 ·  Posted

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

#7 ·  Posted

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

#8 ·  Posted

@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

Share this post


Link to post
Share on other sites

#9 ·  Posted

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

#10 ·  Posted (edited)

@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

Share this post


Link to post
Share on other sites

#11 ·  Posted

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