Sign in to follow this  
Followers 0
Jury

_Word_DocTableWrite to a found location in Word

2 posts in this topic

#1 ·  Posted (edited)

I'm trying to write a table I've created with a GUI into a Word document.  I want the table to be located where at ~ is located in the Word document.  I load a Word document I've created with a ~ about half way down the first page and try the following script using the variations commented out lines 43, 44 and 45.  It works as is placing the table at the top but nowhere else.  Is this possible?

#include <Word.au3>
#include <Array.au3>
#include <MsgBoxConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
Global $oWord = _Word_Create(), $number_rows, $top, $oRange
Global $oDoc = _Word_DocAdd($oWord)

$number_rows = InputBox("Number_of_rows", "Number_of_rows", "2")
Global $row[$number_rows][3]

#Region ### START Koda GUI section ### Form=C:\Users\Joe\Documents\Dropbox\autoit_new\resources\judgment_party_table.kxf
$Form2 = GUICreate("Parties", 623, 449, 192, 114)


For $r = 0 To $number_rows - 1
    $top = $top + 32
    ;$row[$r][0] = "0"
    $row[$r][1] = GUICtrlCreateInput("Party", 16, $top, 585, 21)
    $top = $top + 32
    $row[$r][2] = GUICtrlCreateInput("Appellant or Respondent", 16, $top, 585, 21)
    GUISetState(@SW_SHOW)
Next

$OK = GUICtrlCreateButton("OK", 248, $top + 32, 57, 33)
#EndRegion ### END Koda GUI section ###
GUISetState(@SW_SHOW)
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $OK
            For $k = 0 To $number_rows - 1
                $row[$k][1] = GUICtrlRead($row[$k][1])
                $row[$k][2] = GUICtrlRead($row[$k][2])
            Next
            _ArrayDisplay($row)
            ExitLoop
    EndSwitch
WEnd
;$oRangeFound = _Word_DocFind($oDoc, "~")
;$oRangeFound = _Word_DocFind($oDoc, "~", 0, False, False)
;$oRangeFound = _Word_DocRangeSet($oDoc, 0)
$oRange = _Word_DocRangeSet($oDoc, -2)
_Word_DocTableWrite($oRange, $row, 0)
If @error <> 0 Then Exit MsgBox($MB_SYSTEMMODAL, "Word UDF: _Word_DocTableWrite Example", _
        "Error creating the table." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
MsgBox($MB_SYSTEMMODAL, "Word UDF: _Word_DocTableWrite Example", _
        "Table successfully added to the end of the document.")
Edited by Jury

Share this post


Link to post
Share on other sites



Use

$oRangeFound = _Word_DocFind($oDoc, "~")
$oRange = _Word_DocRangeSet($oDoc, $oRangeFound)

to set the range tp "~" and then insert the table.


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
Sign in to follow this  
Followers 0