Jump to content
MrCheese

Merge word documents

Recommended Posts

MrCheese

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
water

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 (2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
MrCheese

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
water

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 (2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
MrCheese

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
water

Sure:

_Word_DocRangeSet($oDoc, -2)

 


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
MrCheese

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
water

:)


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
MrCheese

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
water

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 (2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
MrCheese

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
water

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

  • Like 1

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
MrCheese

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
water

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 (2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
MrCheese

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
water

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 (2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
water

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 (2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
MrCheese

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
water

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 (2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
MrCheese

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

    • lavascript
      By lavascript
      I have a Word document containing a 9-column table where row 1 is the column headers. My goal is to read the table into a 2d array, remove some rows, update some fields, and add a few rows to the end. The resulting array will likely be a different length. Next, I want to write the data back into the table. If it's easier, I can write the data to a new document from a template containing the same table header with a blank 2nd row.
      Here's my early attempt:
      Local $oWord = _Word_Create() Local $oDoc = _Word_DocOpen($oWord, $sFile) Local $aData = _Word_DocTableRead($oDoc, 1) $aData[3][5] = "Something else" Local $oRange = _Word_DocRangeSet($oDoc, 0) $oRange = _Word_DocRangeSet($oDoc, $oRange, $wdCell, 9) _Word_DocTableWrite($oRange,$aData) This, unfortunately, writes the entire array into the first cell of row 2. What am I doing wrong?
       
    • Subz
      By Subz
      Backstory:
      Our Microsoft Office Templates shared folder was changed from a DFS share to an Isilon share. example:
      Old Server: \\Domain.com\Office\Templates
      New Server: \\Templates.domain.com\Office\Templates
      The team making the changes overlooked that several hundred thousand documents, had been attached to the old template documents.  So when you open a document which has been attached, it will take a couple of minutes to open, while it tries to locate the old server path.  I've been asked to come in and fix it, so after several hours found that the data is being held in document.zip\word\_rels\settings.xml.rels, I now need to replace the old server path with the new server path.  I didn't want to use dom as that would take too long and found a tool wtc https://github.com/NeosIT/wtc which  works perfectly, takes about 8 minutes to scan a single directory with 4000 documents and fix them.  The problem is the documents are all held on sharepoint and they want to retain the file timestamp, which is easy enough, but they also don't want to keep the "Modified By" apparently they don't like seeing all the documents appearing as "Modified by: Subz"  Anyone know of way to retain the "Modified By" info,
    • FrancescoDiMuro
      By FrancescoDiMuro
      Good evening everyone
      I am working with Word UDF ( thanks @water! ), and, especially, with the function _Word_DocFindReplace().
      The replace does work everywhere in the document, but, it does not work in Headers or Footers.
      Am I missing something or am I forced to use the code below?
      I have already looked in the Help file ( about _Word_DocFindReplace() ), but there are no mentions about replace text in Headers/Footers.
      Sub FindAndReplaceFirstStoryOfEachType() Dim rngStory As Range For Each rngStory In ActiveDocument.StoryRanges With rngStory.Find .Text = "find text" .Replacement.Text = "I'm found .Wrap = wdFindContinue .Execute Replace:=wdReplaceAll End With Next rngStory End Sub Thanks everyone in advance


      Best Regards.
    • Benandro
      By Benandro
      Hello,
      im working on a Script that should change a high amount of Word Templates at once.
      Target is to open each Templatefile (.dotx) in a specific folder and do the following steps:
      Add a page break at the end of the document (works) Add a text on the created Page (works) Change the headerstyle to blank for the new page and the following (missing) Add a heading between two specific headings (missing) Can please someone help me to add the 2 functions to the script?
       
      #include <word.au3> #include <File.au3> #include <array.au3> ; wdGoToDirection Const $wdGoToNext = 2 ; wdGoToItem Const $wdGoToPage = 1 ; Created a logfile for tracking/error reporting on my local desktop, though anywhere would work. Needs to be changed or it will error. Global $LogFile = FileOpen("c:\logfiles\test.log", 1) ; This is the network path, change it or this will error as it is. ListFiles ("D:\Templates\") Global $loopend=$aFileList[0] ; Creates an instance of Word for the program to use. Logs any errors associated. Global $oWord = _Word_Create(False, False) If @error <> 0 Then Exit _FileWriteLog($LogFile, "Error creating a new Word application object. @error = " & @error & ", @extended = " & @extended & @crlf) If @extended = 1 Then _FileWriteLog ($LogFile, "MS Word was not running when _Word_Create was called." & @CRLF) Else _FileWriteLog ($LogFile, "MS Word was already running when _Word_Create was called." & @CRLF) EndIf ; Logs and begins loop _FileWriteLog ($LogFile, "Beginning Loop." & @CRLF) For $looper = 1 to $loopend Step +1 _FileWriteLog ($LogFile, "Modifying file: " & $aFileList[$looper], " ") OpenAndModify ("D:\Templates\" & $aFileList[$looper]) Next ; Closes instance of Word _Word_Quit ($oWord) _FileWriteLog ($LogFile, "Program Completed.") ; Begins Function section ; Two functions, Listfiles and OpenAndModify Func ListFiles($FolderPath) ; Function puts all files in the network folder into an array. Logs any errors. _FileWriteLog ($LogFile, "Getting File Information for: " & $FolderPath & @crlf) Global $aFileList = _FileListToArray($FolderPath, "*") If @error = 1 Then _FileWriteLog($LogFile, "Path was invalid." & @crlf) EndIf If @error = 4 Then _FileWriteLog ($LogFile, "No file(s) were found." & @crlf) EndIf EndFunc Func OpenAndModify ($sDocument) ; Function opens file and changes the Page Setup ; Opens the Document Local $oDoc = _Word_DocOpen ($oWord, $sDocument, Default, Default, Default) If @error <> 0 Then _FileWriteLog ($LogFile, "Error opening " & $sDocument & " @error = " & @error & ", @extended = " & @extended & @crlf) & Exit ; Changes Tray Settings ;$oDoc.PageSetup.FirstPageTray = 0 ;$oDoc.PageSetup.OtherPagesTray = 0 ; Add a link to the end of the document and set parameters ; ScreenTip and TextToDisplay Local $oRange = _Word_DocRangeSet($oDoc, -2); Go to end of document $oRange.InsertBreak($wdPageBreak) ;MsgBox($MB_SYSTEMMODAL, "Word UDF: _Word_DocRangeSet Example", "Inserted a break.") $oRange.Text = "«Text»" ; Add a space at the end of the document $oRange = _Word_DocRangeSet($oDoc, -2) If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Word UDF: _Word_DocLinkAdd Example", _ "Error adding a link to the document." & @CRLF & "@error = " & @error & ", @extended = " & @extended) MsgBox($MB_SYSTEMMODAL, "Word UDF: _Word_DocLinkAdd Example", "Baustein wurde an das Ende des Dokuments eingefügt.") ; Saves the document _Word_DocSave($oDoc) _FileWriteLog ($LogFile, "Modification of" & $sDocument & " complete." & @CRLF) EndFunc  
    • Neonovaz
      By Neonovaz
      Hello
       
      Is there anyway to store word documents in Autoit GUI? For example I have a instruction sheet that I want to bundle up with the exe.

      So a user simply clicks the icon and the stored document will launch  (Something like how you can add objects like excel sheets in word documents )

      (I Know we can launch word files from script directory)

       
×