Jump to content

_Word_DocTableWrite to a found location in Word


Go to solution Solved by water,

Recommended Posts

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
  • Solution
Posted

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 2024-07-28 - Version 1.6.3.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 (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

 

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
  • Recently Browsing   0 members

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