MrCheese

Merge word documents

27 posts in this topic

Hi Guys,

Firstly, thanks for your  help in the past.

I have a new activity I need to accomplish.

In summary:

* need to read a cell in excel (containing a file name)

* open the file name in word (as its a word document

*copy the word document

*paste the word document into the master document

*read next cell in excel

... and repeat until you reach the bottom of the column.

 

I can read cells open workbooks etc.

But as far as copying and pasting in word - where is the best place to start, and what functions should I be looking at. Or even if autoit is the right system to use?

Thanks

 

 

 

Share this post


Link to post
Share on other sites



Do you really need to copy all word documents into a master document?
Or could you just add "links" to the master document. When opened the master document reads all linked documents and displays them as a single big document.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (2016-08-18 - Version 1.4.6.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2016-12-04 - Version 1.2.2.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
Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Hi Water,

That would work, providing that you could then save that one master document as a whole document in its own right.

Basically, I have ~ 120 different module documents.

and will have ~ 40 master documents, which are made up of different module documents.

The differences are captured in an excel matrix, utilising a standardised naming conventions for the module file names.

Each master document will need to be distributed (as a whole) for review and feedback, ideally in Doc or docx format to allow tracked changes etc.

Does that help?

Really appreciate your help on this one.

I read ages ago that there is an insert function somewhere, but that's all I can recall.

Share this post


Link to post
Share on other sites

Use _Word_DocRangeSet to set the insertion mark to the desired location.
The returned range object then is used to insert the file

$oRange.InsertFile("C:\temp\insert.docx")

 


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (2016-08-18 - Version 1.4.6.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2016-12-04 - Version 1.2.2.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
Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

how do I best jump from inserting one document, then jumping to the bottom of that newly inserted document, to the inserting another?

is there a _word_docrangeset to jump to the bottom?

Share this post


Link to post
Share on other sites

Sure:

_Word_DocRangeSet($oDoc, -2)

 


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (2016-08-18 - Version 1.4.6.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2016-12-04 - Version 1.2.2.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
Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Excellent.

I'll work on some code over the next 24 hours.

Thanks for your help so far.

Share this post


Link to post
Share on other sites

:)


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (2016-08-18 - Version 1.4.6.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2016-12-04 - Version 1.2.2.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
Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

I'm not sure why, but the word documents aren't opening.

See the attached zip for all the dummy test files I'm using.

i wanted to create a fresh document, add the subdocuments and save it as a different file name at the end.

 

Ideally wanted to add each document by reading across the one row, then move to the next row.

Since that didn't seem to work, I transposed the data to then read down the column, then start on the next column.

#include <MsgBoxConstants.au3>
#include <Word.au3>
;~ #include <Array.au3>
#include <Excel.au3>
;~ #include <Timers.au3>
;~ #include <Date.au3>


;----------------------- CHANGE BELOW --------------------;
$nExcelBook = "matrix"
$cBookLocalName = @ScriptDir & "\Test\" & $nExcelBook & ".xlsx"
$version = "v1"
$vpn = False
$onerow = True
;----------------------- CHANGE ABOVE --------------------;
$columnstart = "A"
$rowstart = 4
$oWorkbook1 = 0

$eComment = "H"

OpenExcel()

;Local $oDoc = _Word_DocOpen($oWord, @ScriptDir & "\Test\Test.docx", Default, Default, True)

;sleep(5000)
$run = 0
While 1
    $run = $run + 1
    $column = $columnstart
    $row = $rowstart
    if $run = 2 then $column = "B"
    Local $oRange, $oWord = _Word_Create()
    $eAreaName = _Excel_RangeRead($oWorkbook1, Default, $column & $row)
    If $eAreaName = "" Then
        _Excel_RangeWrite($oWorkbook1, $oWorkbook1.ActiveSheet, "Dataload completed", $eComment & $row)
        ExitLoop
    EndIf
    _Word_DocAdd($oWord)
    ; new word document
    ;insertdoc()
    _Word_DocRangeSet($oWord, -2)
    $oRange.InsertFile(@ScriptDir & "\Test\" & $eAreaName & ".docx")
    ;$column = $column + 1
    While 1
        $row = $row + 1
        $eAreaName = _Excel_RangeRead($oWorkbook1, Default, $column & $row)
        If $eAreaName = "" Then
            _Excel_RangeWrite($oWorkbook1, $oWorkbook1.ActiveSheet, "Row Completed", $eComment & $row)
            ExitLoop
        EndIf
        _Word_DocRangeSet($oWord, -2)
        $oRange.InsertFile(@ScriptDir & "\Test\" & $eAreaName & ".docx")
        ;insertdoc()
        ;$row = $row + 1
        ;$column = $column + 1
    WEnd
    $eAreaName = _Excel_RangeRead($oWorkbook1, Default, 1 & $row)
    _Word_DocSaveAs($oWord, @ScriptDir & "\Test\Final.doc");" & $eAreaName & ".doc")
    $rowcomplete = True
    If $onerow = True Then
        ExitLoop
    EndIf
    ;$row = $row + 1
WEnd

MsgBox(0, "Completed", "Document creator has completed.")

Func insertdoc()

EndFunc   ;==>insertdoc

Func OpenExcel()
    ; Create application object and open an example workbook
    _Excel_BookClose($oWorkbook1)
    Global $oExcel = _Excel_Open()
    If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_RangeCopy Example", "Error creating the Excel application object." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
    ; Open Workbook 1
    Global $oWorkbook1 = _Excel_BookOpen($oExcel, $cBookLocalName)
    If @error Then
        MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_RangeCopy Example", "Error opening workbook '" & @ScriptDir & "Book1.xlsx'." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
        _Excel_Close($oExcel)
        Exit
    EndIf
EndFunc   ;==>OpenExcel

 

Test.zip

Share this post


Link to post
Share on other sites

#10 ·  Posted

The following script works for me. Please copy all files into directory C:\temp\Merge_Word

Test2.zip


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (2016-08-18 - Version 1.4.6.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2016-12-04 - Version 1.2.2.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
Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#11 ·  Posted

awesome.. so simple right?

However, can I make it read across columns in excel, and then say at the end (say column M), jump to the next row?

and how could i commence reading/inserting from column B?

and lastly, how do I insert a page break after each insertion?

 

not sure what : $wdPageBreak   would refer to?

$oRange.InsertBreak($wdPageBreak)

 

Share this post


Link to post
Share on other sites

#12 ·  Posted

Something like this?
$wdPageBreak is one of the Word enumerations you can find in the WordConstants.au3 (an include which gets called by Word.au3).

Test.zip

1 person likes this

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (2016-08-18 - Version 1.4.6.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2016-12-04 - Version 1.2.2.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
Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#13 ·  Posted (edited)

its getting there!! thanks for your help.

One thing, can I have it so row 1 is its own document that is saved according to its file name located in the last cell? (column D)

and then row 2 is its own document... row 3 is its own etc.

Test (2).zip

Edited by MrCheese

Share this post


Link to post
Share on other sites

#14 ·  Posted

That's easy:

#include <Word.au3>
#include <Excel.au3>

Global $oExcel = _Excel_Open(False)
Global $oWorkbook = _Excel_BookOpen($oExcel, @ScriptDir & "\test.xlsx")
Global $aDocuments = _Excel_RangeRead($oWorkbook)
_Excel_Close($oExcel, False)
Global $oWord = _Word_Create()
Global $oDocMaster, $oDoc, $i, $j
For $i = 0 To UBound($aDocuments, 1) - 1
    $oDocMaster = _Word_DocAdd($oWord) ; Start a new document for every row
    Global $oRange = _Word_DocRangeSet($oDocMaster, -1)
    For $j = 0 To UBound($aDocuments, 2) - 2 ; last element of the row holds the path of $oDocMaster
        If $aDocuments[$i][$j] <> "" Then
            $oRange.InsertFile($aDocuments[$i][$j])
            $oRange = _Word_DocRangeSet($oDocMaster, -2)
            $oRange.InsertBreak($WdPageBreak)
        EndIf
    Next
    ConsoleWrite($aDocuments[$i][UBound($aDocuments, 2) - 1] & @CRLF)
    _Word_DocSaveAs($oDocMaster, $aDocuments[$i][UBound($aDocuments, 2) - 1], $WdFormatDocumentDefault) ; Save master document
    ConsoleWrite(@error & @CRLF)
    _Word_DocClose($oDocMaster) ; Close document
Next
_Word_Quit($oWord)

N.B. The Excel file needs to hold the full path to the inptu and output Word document e.g. C:\temp\Test1.docx


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (2016-08-18 - Version 1.4.6.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2016-12-04 - Version 1.2.2.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
Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#15 ·  Posted (edited)

hi,

thanks for that :)

unfortunately i'm getting a error on the insert file function:

"C:\temp\wordmerge_v3.au3" (15) : ==> The requested action with this object has failed.:
$oRange.InsertFile($aDocuments[$i][$j])
$oRange^ ERROR

 

as you can tell in the data load file the names contain the file path of both the inserting and saving.

Any ideas?

Thanks again.

#include <Word.au3>
#include <Excel.au3>

Global $oExcel = _Excel_Open(False)
Global $oWorkbook = _Excel_BookOpen($oExcel, @ScriptDir & "\test.xlsx")
Global $aDocuments = _Excel_RangeRead($oWorkbook)
_Excel_Close($oExcel, False)
Global $oWord = _Word_Create()
Global $oDocMaster, $oDoc, $i, $j
For $i = 0 To UBound($aDocuments, 1) - 1
    $oDocMaster = _Word_DocAdd($oWord) ; Start a new document for every row
    Global $oRange = _Word_DocRangeSet($oDocMaster, -1)
    For $j = 0 To UBound($aDocuments, 2) - 2 ; last element of the row holds the path of $oDocMaster
        If $aDocuments[$i][$j] <> "" Then
            $oRange.InsertFile($aDocuments[$i][$j])
            $oRange = _Word_DocRangeSet($oDocMaster, -2)
            $oRange.InsertBreak($WdPageBreak)
        EndIf
    Next
    ConsoleWrite($aDocuments[$i][UBound($aDocuments, 2) - 1] & @CRLF)
    _Word_DocSaveAs($oDocMaster, $aDocuments[$i][UBound($aDocuments, 2) - 1], $WdFormatDocumentDefault) ; Save master document
    ConsoleWrite(@error & @CRLF)
    _Word_DocClose($oDocMaster) ; Close document
Next
_Word_Quit($oWord)

wordmerge_v3.au3

dataload2.xlsx

Edited by MrCheese

Share this post


Link to post
Share on other sites

#16 ·  Posted (edited)

Does this work for you? It ignores files which do not exist:

#include <Word.au3>
#include <Excel.au3>

Global $oExcel = _Excel_Open(False)
Global $oWorkbook = _Excel_BookOpen($oExcel, @ScriptDir & "\dataload2.xlsx")
Global $aDocuments = _Excel_RangeRead($oWorkbook)
_Excel_Close($oExcel, False)
Global $oWord = _Word_Create()
Global $oDocMaster, $oDoc, $i, $j
For $i = 0 To UBound($aDocuments, 1) - 1
    $oDocMaster = _Word_DocAdd($oWord) ; Start a new document for every row
    Global $oRange = _Word_DocRangeSet($oDocMaster, -1)
    For $j = 0 To UBound($aDocuments, 2) - 2 ; last element of the row holds the path of $oDocMaster
        If $aDocuments[$i][$j] <> "" And FileExists($aDocuments[$i][$j]) Then
            $oRange.InsertFile($aDocuments[$i][$j])
            $oRange = _Word_DocRangeSet($oDocMaster, -2)
            $oRange.InsertBreak($WdPageBreak)
        EndIf
    Next
    _Word_DocSaveAs($oDocMaster, $aDocuments[$i][UBound($aDocuments, 2) - 1], $WdFormatDocumentDefault) ; Save master document
    _Word_DocClose($oDocMaster) ; Close document
Next
_Word_Quit($oWord)

 

Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (2016-08-18 - Version 1.4.6.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2016-12-04 - Version 1.2.2.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
Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#17 ·  Posted

Another question:
We now have an empty page at the end of the master document. Should this empty page be removed?


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (2016-08-18 - Version 1.4.6.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2016-12-04 - Version 1.2.2.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
Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#18 ·  Posted

if it can be removed easily then yes, but its okay if not.

awesome so far!

ill run it a few times and see how it goes.

Share this post


Link to post
Share on other sites

#19 ·  Posted

This version deletes the last (empty) page:

#include <Word.au3>
#include <Excel.au3>

Global $oExcel = _Excel_Open(False)
Global $oWorkbook = _Excel_BookOpen($oExcel, @ScriptDir & "\dataload2.xlsx")
Global $aDocuments = _Excel_RangeRead($oWorkbook)
_Excel_Close($oExcel, False)
Global $oWord = _Word_Create()
Global $oDocMaster, $oDoc, $i, $j, $oRange
For $i = 0 To UBound($aDocuments, 1) - 1
    $oDocMaster = _Word_DocAdd($oWord) ; Start a new document for every row
    $oRange = _Word_DocRangeSet($oDocMaster, -1)
    For $j = 0 To UBound($aDocuments, 2) - 2 ; last element of the row holds the path of $oDocMaster
        If $aDocuments[$i][$j] <> "" And FileExists($aDocuments[$i][$j]) Then
            $oRange.InsertFile($aDocuments[$i][$j])
            $oRange = _Word_DocRangeSet($oDocMaster, -2)
            $oRange.InsertBreak($WdPageBreak)
        EndIf
    Next
    ; Go to the end of the document and delete the empty page
    $oRange = _Word_DocRangeSet($oDocMaster, -2, $wdCharacter, -3)
    $oRange.Delete
    ; Save and close master document
    _Word_DocSaveAs($oDocMaster, $aDocuments[$i][UBound($aDocuments, 2) - 1], $WdFormatDocumentDefault)
    _Word_DocClose($oDocMaster)
Next
_Word_Quit($oWord)

 


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (2016-08-18 - Version 1.4.6.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2016-12-04 - Version 1.2.2.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
Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#20 ·  Posted

OK

so in the excel book, i added a column at the start which contained the names of some "base" document (title page, contents, revisions etc). (doc attached).

but now the cpu cycles up, the autoit takes much longer to complete and no output documents are found :(:( 

i did have blank cells, but I removed them as it wasn't working; but even after removal its not working.

also i noticed all my documents are .doc, and not docx. does this cause a problem?

dataload2.xlsx

NWoW-Deliverable-Template-Division-WS.doc

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

  • Similar Content

    • Duck
      Attempting to read each line of an office document (.doc, .docx, .xls, .xlsx) - Similarly to a FileReadLine()
      By Duck
      I'm attempting to read each line of a word document and assign the line to a variable. Similarly to how you can read a line from a text file (.txt or .csv) using FileReadLine(). So far i have been unsuccessful in reading from a .doc/.docx file, nor have i found any documentation that has helped.

      In searching for a solution i did find a function to convert the word doc to a text file, however my script is for (PCI) auditing purposes and i do not want to create a new file on the HDD.  I have also read through the _Word UDF help files... Unless im not understanding the _Word UDF correctly, I did not see anything that functions similarly to the FileReadLine function.
      Any help/advice is greatly appreciated!  
       
      Here is what i have been attempting to do(doesn't work): 
       
      #include <file.au3> #include <Array.au3> #include <LuhnCheck.au3> #include <Excel.au3> #include <Word.au3> Global $sPath = 'C:\Users\' Global $filePath Global $pii = @ScriptDir & '\pii_CreditCard.csv' Global $filesArray = _FileListToArrayRec($sPath , '*.txt;*.csv;*.doc;*.docx;*.xls;*.xlsx',1,1,0,2) For $i = 1 to $filesArray[0] ;Loop through file extensions and add files to the fileArray ;Assign the position in the filesArray to filePath (filePath is set to full path in FileListToArrayRec) $filePath = $filesArray[$i] readFile($filePath) Next Func readFile($file) If StringInStr($file, '.txt') Or StringInStr($file, '.csv') Then ; .txt file readTxtFile($file) ElseIf StringInStr($file, '.doc') Then ; .doc & .docx files ;============================================== part that does not work========================= Local $oWord = _Word_Create() ;$openFile = FileOpen($file, 0); While 1 Local $line = FileReadLine(_Word_DocOpen($oWord, $file, Default, Default, True)) If @error = -1 Then ExitLoop ;lookForCreditCardNumbers($line) MsgBox(0,0, $line) WEnd FileClose($openFile) ;============================================== part that does not work========================== EndIf EndFunc Func readTxtFile($fileToOpen) $openFile = FileOpen($fileToOpen, 0); open file for reading and assing it to the openFile variable While 1 Local $line = FileReadLine($openFile) If @error = -1 Then ExitLoop lookForCreditCardNumbers($line) WEnd FileClose($openFile) EndFunc Func lookForCreditCardNumbers($evaluateString) $aResult = StringRegExp($evaluateString, '[4|5|3|6][0-9]{15}|[4|5|3|6][0-9]{3}[-| ][0-9]{4}[-| ][0-9]{4}[-| ][0-9]{4}', $STR_REGEXPARRAYMATCH) If Not @error Then Local $newString1 = StringReplace($aResult[0], ' ', '') ;remove spaces Local $newString2 = StringReplace($newString1, '-', '') ;remove dashes Local $bool = _LuhnValidate($newString2) ; Check possible CC number against the Luhn algorithm If $bool = 'True' Then Local $piiCSV = FileOpen($pii, 1) ;open text file for appending/writing, 1 FileWriteLine($piiCSV, $filePath & ', ' & $newString2) FileClose($piiCSV) EndIf EndIf EndFunc  
    • StillLearningThisStuff
      Merge 2 x 1d temp arrays into one 2d array
      By StillLearningThisStuff
      Hello all,
      Summary: I have a basic piece of code that is to be a part of a much larger project; I just can't seem to get the right output. I'm retrieving two lots of powershell data into 2 x 1d arrays and trying to add them into a single 2d array. Retrieving the data together into the 2d array seemed harder, due to the application names varying too much to string split. Data being pulled is application name and GUID. From here I will use this info in a drop down box and an uninstall button to run the required command to remove the selected software (have this sorted already).
      Problem: When I merge the data it doesn't put the application name and GUID on the same row in differing columns eg. my test box has 24 applications plus some superfluous data from Powershell to be cleaned up by the _arraydeletes. Instead I end up with an array with 58 rows and 2 columns; whereas my temp 1d arrays have 28 rows. As you can see I've tried both _ArrayInsert and _ArrayAdd but I still get the same result.
      Question: Is there something that I'm doing wrong in putting the data into the 2d array or do I just need to do some more post processing to tidy it up and align the names and GUIDs?
      Code:
      #include <Array.au3> $Cmd1 = (" /c Powershell.exe " & Chr(34) & "Get-WmiObject -Class win32reg_addremoveprograms | where {$_.ProdID -like " & Chr(34) & Chr(123) & Chr(42) & Chr(125) & Chr(34) & "} | select DisplayName" & Chr(34)) $Cmd2 = (" /c Powershell.exe " & Chr(34) & "Get-WmiObject -Class win32reg_addremoveprograms | where {$_.ProdID -like " & Chr(34) & Chr(123) & Chr(42) & Chr(125) & Chr(34) & "} | select ProdID" & Chr(34)) Global $aNameGUID[1][2] ;_ArrayDisplay($aNameGUID) ReadApps($Cmd1,0) ;_ArrayDisplay($aNameGUID) ReadApps($Cmd2,1) _ArrayDisplay($aNameGUID) Terminate() Func ReadApps($Command,$col) $DOS = Run(@ComSpec & $Command, "", @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD) ProcessWaitClose($DOS) $DOSOut = StdoutRead($DOS) ;MsgBox(0,"Data",$DOSOut) ;Show the line items that we want in the array Local $tmpArray = StringSplit(StringTrimRight(StringStripCR($DOSOut), StringLen(@CRLF)), @CRLF) If @error Then MsgBox(0,"FAIL","I failed to find objects") Exit Else _ArrayDisplay($tmpArray) EndIf ;_ArrayDelete($tmpArray, 3) ;_ArrayDelete($tmpArray, 2) ;_ArrayDelete($tmpArray, 1) ;$tmpArray[0] = $tmpArray[0] - 3 For $i = 0 To UBound($tmpArray) - 1 ;_ArrayAdd($aNameGUID, $tmpArray[$i], $col) _ArrayInsert($aNameGUID, 0, $tmpArray[$i], $col) Next $tmpArray = 0 EndFunc ;==>ReadApps While 1 Sleep(1500) WEnd Func Terminate() Exit 0 EndFunc ;==>Terminate Thanks in advance,
      Luxyboy
    • kcvinu
      How to make a newline in Word with COM
      By kcvinu
      Hi all (Especially @water)
      I wonder how to do this task in word from autoit.
      Assume that i pasted some text into word with this code.
      Local $oWord = ObjGet("","Word.Application") Local $wRangeObj = _Word_DocRangeSet($oWord, 0) Local $data = ClipGet() $wRangeObj.Text = $data $wRangeObj.Font.Bold = True So far so good. Now, i need to enter a new line in word and turn the Font.Bold = False.  
      Currently, i did it with activating the word window and Send() function. But i would like to do it with the help of COM object. How can i do that ? 
    • TheDcoder
      Cannot save word document - Strange/Unknown error
      By TheDcoder
      Hello, I am trying to save an word document but it won't work , This is my REALLY simple script:
      #include <Word.au3> Global $oWord = _Word_Create(False, True) _Word_DocSaveAs($oWord) MsgBox(0, @error, @extended) And my MsgBox:

      I know that its a COM error because @error is set 2... but what about the COM error code? I cannot find anything related to -2147352570!
    • aiter
      word com error trapping possible bug in udf
      By aiter
      I am testing intercepting com errors in Word and I have found a possible bug in the UDF, it might not be a bug it just means a workaround.
      I have found the com error bug in _Word_Create
      Func _Word_Create($bVisible = Default, $bForceNew = Default) Local $oAppl, $bApplCloseOnQuit = False If $bVisible = Default Then $bVisible = True If $bForceNew = Default Then $bForceNew = False If Not $bForceNew Then $oAppl = ObjGet("", "Word.Application") <------- here is the line which causees com error This happens in the following example
      #include <Word.au3> main() func main() local $oErrorHandler = ObjEvent("AutoIt.Error", "_ErrFunc") $oWord = _Word_Create() $oDoc = _Word_DocOpen($oWord, @ScriptDir & "\Dear.docx", False, Default, True) $myrange = $oDoc.Range $myrange.Select sleep(3000) _Word_DocClose($oDoc) _Word_Quit($oWord) endfunc ; User's COM error function. Will be called if COM error occurs Func _ErrFunc($oError) ; Do anything here. ConsoleWrite(@ScriptName & " (" & $oError.scriptline & ") : ==> COM Error intercepted !" & @CRLF & _ @TAB & "err.number is: " & @TAB & @TAB & "0x" & Hex($oError.number) & @CRLF & _ @TAB & "err.windescription:" & @TAB & $oError.windescription & @CRLF & _ @TAB & "err.description is: " & @TAB & $oError.description & @CRLF & _ @TAB & "err.source is: " & @TAB & @TAB & $oError.source & @CRLF & _ @TAB & "err.helpfile is: " & @TAB & $oError.helpfile & @CRLF & _ @TAB & "err.helpcontext is: " & @TAB & $oError.helpcontext & @CRLF & _ @TAB & "err.lastdllerror is: " & @TAB & $oError.lastdllerror & @CRLF & _ @TAB & "err.scriptline is: " & @TAB & $oError.scriptline & @CRLF & _ @TAB & "err.retcode is: " & @TAB & "0x" & Hex($oError.retcode) & @CRLF & @CRLF) EndFunc ;==>_ErrFunc This script causes a com error to occur and it has the following error
      test.au3 (53) : ==> COM Error intercepted ! err.number is: 0x80020006 err.windescription: Unknown name. err.description is: err.source is: err.helpfile is: err.helpcontext is: err.lastdllerror is: 0 err.scriptline is: 53 err.retcode is: 0x00000000 Line 53 is
      If Not $bForceNew Then $oAppl = ObjGet("", "Word.Application") as I mentioned above.
      When I force a new instance of Word, no error occurs eg
      #include <Word.au3> main() func main() local $oErrorHandler = ObjEvent("AutoIt.Error", "_ErrFunc") $oWord = _Word_Create(True,True) $oDoc = _Word_DocOpen($oWord, @ScriptDir & "\Dear.docx", False, Default, True) $myrange = $oDoc.Range $myrange.Select sleep(3000) _Word_DocClose($oDoc) _Word_Quit($oWord) endfunc So it seems that if I want to open up  existing Word instance (use _Word_Create() ) I will have to create my own _Word_Open to bypass this problem.
      (If Word is already open the problem will not occur)
      Comment?