Mrtn Posted November 30, 2011 Share Posted November 30, 2011 I need some help here, I'm having trouble with my Word object: Arrays are filled, word document opens fine, $oWordApp is object , first loop "For $j = 0" works (first array element is processed in Word) but then I get the following error : The requested action with this object has failed.: $oWordApp.Selection.TypeText($aStreng[$j]) $oWordApp.Selection.TypeText($aStreng[$j])^ ERROR i'm a little bit lost here.. please help oh, and the code : expandcollapse popupIf FileExists($sFilePath1) Then ;---> check of bestand bestaat If WinExists($Project & " Strenggegevens.xls") Then MsgBox(262144, "", "Excel bestand is open") WinClose($Project & " Strenggegevens.xls") WinWaitClose($Project & " Strenggegevens.xls") $oExcel = _ExcelBookOpen($sFilePath1) Else ;---> open excel bestand $oExcel = _ExcelBookOpen($sFilePath1) EndIf Else MsgBox(262144, "error", "Strenggegevens bestaan niet, aan het werk luie hond! ;)", 2) EndIf If IsObj($oExcel) Then $nStrengen = _ExcelReadCell($oExcel, 1, 1) $oWordApp = _WordCreate($templateWord) $oWordApp.activedocument.SaveAs($sDirProjecten & $Project & "\" & $Project & " StrengRapport.doc") For $i = 4 To $nStrengen $aStreng = _ExcelReadArray($oExcel, $i, 1, 33) ;~ _ArrayDisplay($aStreng) For $j = 0 To UBound($aStreng) - 1 If IsObj($oWordApp) Then ;<--- control line!! $oWordApp.Selection.TypeText($aStreng[$j]) $oWordApp.Selection.TypeParagraph Sleep(100) ConsoleWrite($aStreng[$j] & @CRLF) EndIf Next $oWordApp.Selection.TypeParagraph Next $oWordApp.Selection.TypeParagraph $oWordApp.Selection.TypeText("----------------") $oWordApp.Selection.TypeParagraph $oWordApp.Selection.TypeText("totaal aantal strengen = " & $nStrengen) Endif Link to comment Share on other sites More sharing options...
Clark Posted December 1, 2011 Share Posted December 1, 2011 I played with this for a while, but could not replicate an issue. My best guess without seeing the input file is that one of the cells that you are reading from your Excel spreadsheets is either blank, or does not exist in the word document to select. Link to comment Share on other sites More sharing options...
Mrtn Posted December 1, 2011 Author Share Posted December 1, 2011 (edited) there are blank cells in my excel dcument indeed, those array elements are empty. I did check for empty array elements by For $j = 0 To UBound($aStreng) - 1 If IsObj($oWordApp) Then If $aStreng[$j] = "" Then ;<----- check if array element is empty MsgBox(0, "", "leeg") $oWordApp.Selection.TypeText("empty") $oWordApp.Selection.TypeParagraph Else $oWordApp.Selection.TypeText($aStreng[$j]) $oWordApp.Selection.TypeParagraph EndIf ConsoleWrite($aStreng[$j] & @CRLF) EndIf Next if i run this, the loop stops after the first empty array element? ("empty" is typed in word document) I'm out of clues... Edited December 1, 2011 by Mrtn Link to comment Share on other sites More sharing options...
water Posted December 1, 2011 Share Posted December 1, 2011 As " " <> ""I would strip off all spacesIf StringStripWS($aStreng[$j],8) = "" Then My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
Mrtn Posted December 1, 2011 Author Share Posted December 1, 2011 Thanks for the tip water, i will implement this in my code, however the cells in my excel document are filled with autoit, so I know that they are empty. Maybe it is better to construct a string with my array and then write the consctructed string to word? Link to comment Share on other sites More sharing options...
water Posted December 1, 2011 Share Posted December 1, 2011 I'm sure it's worth a try and might be must faster too. My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now