Jump to content

Recommended Posts

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

 

 

 

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 (NEW 2021-11-10 - Version 1.6.0.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (NEW 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 (NEW 2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2019-12-03 - Version 1.5.1.0) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

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.

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 (NEW 2021-11-10 - Version 1.6.0.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (NEW 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 (NEW 2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2019-12-03 - Version 1.5.1.0) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to post
Share on other sites

Sure:

_Word_DocRangeSet($oDoc, -2)

 

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2021-11-10 - Version 1.6.0.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (NEW 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 (NEW 2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2019-12-03 - Version 1.5.1.0) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to post
Share on other sites

:)

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2021-11-10 - Version 1.6.0.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (NEW 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 (NEW 2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2019-12-03 - Version 1.5.1.0) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

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

Link to post
Share on other sites

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 (NEW 2021-11-10 - Version 1.6.0.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (NEW 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 (NEW 2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2019-12-03 - Version 1.5.1.0) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to post
Share on other sites

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)

 

Link to post
Share on other sites

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

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2021-11-10 - Version 1.6.0.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (NEW 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 (NEW 2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2019-12-03 - Version 1.5.1.0) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to post
Share on other sites

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 (NEW 2021-11-10 - Version 1.6.0.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (NEW 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 (NEW 2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2019-12-03 - Version 1.5.1.0) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to post
Share on other sites

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
Link to post
Share on other sites

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 (NEW 2021-11-10 - Version 1.6.0.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (NEW 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 (NEW 2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2019-12-03 - Version 1.5.1.0) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to post
Share on other sites

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 (NEW 2021-11-10 - Version 1.6.0.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (NEW 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 (NEW 2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2019-12-03 - Version 1.5.1.0) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to post
Share on other sites

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 (NEW 2021-11-10 - Version 1.6.0.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (NEW 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 (NEW 2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2019-12-03 - Version 1.5.1.0) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to post
Share on other sites

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

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

    No registered users viewing this page.

  • Similar Content

    • By diff
      Hello,
       
      so I have started to learn to use the Word UDF and got issue to add my pictures after exact paragraphs. I was searching in the forum for the solution, checked with examples and still I don't understand how to add pictures after paragraph in new line.
       
      My word document has like 8 pages and for example on page I have paragraph named "My examples:" and here starts my problem.
       
      I have tried to do this:
      #include <Word.au3> Local $oWord = _Word_Create() Local $oDoc = _Word_DocOpen($Word, @ScriptDir & "\examples.docx", Default, Default, True) $oSearchRange = _Word_DocRangeSet($oDoc, -1, $wdParagraph, 0) $oRangeFound = _Word_DocFind($oDoc, "My examples:", $oSearchRange) _Word_DocPictureAdd($oDoc, @ScriptDir & "\pic1.jpg", Default, Default, $oRangeFound) And here the picture adds before the paragraph My examples: on same line and looks like
      {pic1}My Examples:
       
      What I want to see is:
      My examples:
      {PICTURE IN NEW LINE} which is pic1.jpg from my code.
       
      How I can do that? I want to add 3 pictures in a row in new line each like:
      My examples:
      {pic1.jpg}
      {pic2.jpg}
      {pic3.jpg}
       
      Hope I explained this well, but you can ask me if you need any additional information to clarify.
    • By ahha
      I'm trying to get the number of columns in a specific row in a Word table and am stuck.   I need a push.  Program below and Word file attached.
      Thanks.
      #AutoIt3Wrapper_run_debug_mode=Y ;use this to debug in console window #include <Word.au3> $oWord = _Word_Create(True, True) ;Create Word application object, make it visible, and force a new instance of Word $oDoc = _Word_DocOpen($oWord, @ScriptDir&"\ColumnTest.docx", Default, Default, True) ;Open the Word document $iTablesCount = $oDoc.Tables.Count ;get Tables count in $oDoc Pause("$iTablesCount = '" & $iTablesCount & "'") $iRowCount = $oDoc.Tables.Item(1).Rows.Count ;Table hard coded $iColCount = $oDoc.Tables.Item(1).Columns.Count Pause("Table#1 $iRowCount = '" & $iRowCount & " $iColCount = '" & $iColCount & "'") ;trying to get the number of columns in each row ;$ColCountInRow = $oDoc.Tables.Item(1).Rows(1).Columns.Count ;this fails and read somewhere to use Cells.Count $ColCountInRow = $oDoc.Tables.Item(1).Rows(1).Cells.Count ;hard code Row 1 <<<<< ERROR here ;this is the error I get ;: ==> The requested action with this object has failed.: ;$ColCountInRow = $oDoc.Tables.Item(1).Rows(1).Cells.Count ;$ColCountInRow = $oDoc.Tables.Item(1)^ ERROR Pause("Row 1 has " & $ColCountInRow & " Columns") Exit Func Pause($text="") MsgBox(262144, "DEBUG", "Paused: " & $text) EndFunc  
      ColumnTest.docx
    • By Fenzik
      Hello!
      i wrote this function as alternative to using the Com Object or Commandline version of this project, discussed also earlyer on this forum.
      Project site - http://ebstudio.info/home/xdoc2txt.html
      Advantage of this implementation is that you do not need to register Com dll, using regsvr32.
      But you still need the project Dll (xd2txlib.dll).
      Enjoy!
      ; #FUNCTION# ==================================================================================================================== ; Name ..........: _ExtractText ; Description ...: Extracts text from advanced documment formats (Doc, Docx, ODT, XLS, ...) ; Syntax ........: _ExtractText($sFilename[, $bProperties = False[, $hDll = 0]]) ; Parameters ....: $sFilename - a string value. ; $bProperties - [optional] a boolean value. Default is False. If True, documment properties will be returned instead of the text. ; $hDll - [optional] a handle value. Default is 0. Optional handle to previously opened xd2txlib.dll. By default the xd2txlib.dll (Expected in @scriptdir) will be opened and closed during the function call. ; Return value .: String, containing the text or documment properties or empty string and Error as follows: ;1 - The file does not exists. ;2 - Error during opening xd2txlib.dll. ;3 - No text returned. ; Author ........: Fenzik ; Modified ......: ; Remarks .......: Project site - http://ebstudio.info/home/xdoc2txt.html ; Related .......: ; Link ..........: ; Example .......: No ; =============================================================================================================================== Func _ExtractText($sFilename, $bProperties = False, $hDll = 0) If Not FileExists($sFilename) Then Return SetError(1, "", "") Local $bLoaded = False If $hDll = 0 Then $hDll = DllOpen(@scriptdir&"\xd2txlib.dll") If $hDll = -1 Then Return SetError(2, "", "") $bLoaded = True Endif $aResult = DllCall($hDll, "int:cdecl", "ExtractText", "WSTR", $sFilename, "BOOL", $bProperties, "WSTR*", "") If $aResult[0] = 0 Then Return SetError(3, "", "") If $bLoaded = True Then DllClose($hDll) Return $aResult[3] EndFunc  
       
      xd2txlib-example.zip
    • 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?
       
    • 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,
×
×
  • Create New...