entropicarbon Posted July 3, 2006 Share Posted July 3, 2006 Hello, I discovered autoIt while looking for a way to batch convert about 3000 word documents to RTF files. on a google forum I found the following script; but it breaks at line 30 when i try to run it, and at line 28 when I check the syntax with ScITE. Any ideas?? I used an application (PrintFolder) to create a list of the DOC files, which I copied (to the clipboard?) Is there any other way to start this script? Am i even starting it correctly? heres the code: expandcollapse popup; ============================================== ; AutoIt script to convert Microsoft Word documents to ; rich text format using WordPad. Each RTF file is stored ; in the same directory as its originating MS Word document, ; and has the same file name with a RTF extension. ; The list of Word document names is acquired from the ; clipboard - preferably fully qualified. ; In the interests of brevity for posting to the NG, this ; script performs no error checking - eg. if RTF file ; already exists. It also assumes that Word documents have ; a file extension of ".DOC". Anyone wishing to make serious ; use of this script is advised to add some minimal error ; processing. ; ; I have carried out a reasonable level of testing but ; cannot be held responsible for any adverse consequences ; arising from use of this script. Use at your own risk. ; ; Oh yes, one more caveat. I built and tested this under ; Windows 2000 Professional. I am unable to say how or ; whether it will perform under other flavours of Windows. ; ; Adrian Carter ; Sept 18, 2003 ; ============================================== ; Look for window title text anywhere in string SetTitleMatchMode, 2 ; Capture list of Word doc names from clipboard; SetEnv,TheDocs,%Clipboard% ; Start WordPad & wait for it to start Run, "C:\\Program Files\\Windows NT\\Accessories\\WordPad.exe" WinWaitActive, - WordPad Start: ; Extract next Word document StringLen, L, TheDocs IfEqual, L, 0, GoTo, ExitPoint StringGetPos, P, TheDocs,\n IfEqual, ErrorLevel, 1, GoTo, LastOne SetEnv, RemLen, %L% EnvSub, RemLen, 1 EnvSub, RemLen, %P% EnvSub, P, 1 StringLeft, NextDoc, TheDocs, %P% StringRight, Remainder, TheDocs, %RemLen% StringReplace, NextRTF, NextDoc,.doc,.rtf SetEnv, TheDocs, %Remainder% ; Up to here, we were just building filenames. ; Now we get WordPad to open the doc and save the rtf GoSub, Convert GoTo, Start LastOne: ; Set doc & rtf names SetEnv, NextDoc, %TheDocs% StringReplace, NextRTF, NextDoc,.doc,.rtf ; Execute conversion GoSub, Convert GoTo, ExitPoint Convert: ; Shortcut to File|Open Send,^o ; Type name of Word doc Send,%NextDoc% ; Press ENTER key Send,{ENTER} ; Shortcut to File|SaveAs Send,!fa ; Type name of RTF file Send,%NextRTF% ; Press ENTER key Send,{ENTER} Return ExitPoint: ; Close WordPad Send,!fx Exit ; ============================================== Link to comment Share on other sites More sharing options...
w0uter Posted July 3, 2006 Share Posted July 3, 2006 this is v2 My UDF's:;mem stuff_Mem;ftp stuff_FTP ( OLD );inet stuff_INetGetSource ( OLD )_INetGetImage _INetBrowse ( Collection )_EncodeUrl_NetStat_Google;random stuff_iPixelSearch_DiceRoll Link to comment Share on other sites More sharing options...
entropicarbon Posted July 3, 2006 Author Share Posted July 3, 2006 this is v2 thats easy. Is converting the script to V3 difficult for someone who knows whats what?Ive been messing around with it, but... Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted July 3, 2006 Moderators Share Posted July 3, 2006 V3 comes with a V2 to V3 converter, have you tried that yet? Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
entropicarbon Posted July 3, 2006 Author Share Posted July 3, 2006 (edited) V3 comes with a V2 to V3 converter, have you tried that yet?Had not tried that! Actually, i uninstalled v3 and installed v2; and it gets to the Open WordPad and just kindof hangs...Ill try the 2to3 converter. Thanks! Edited July 3, 2006 by entropicarbon Link to comment Share on other sites More sharing options...
entropicarbon Posted July 3, 2006 Author Share Posted July 3, 2006 Had not tried that! Actually, i uninstalled v3 and installed v2; and it gets to the Open WordPad and just kindof hangs... Ill try the 2to3 converter. Thanks! Apparently, its not the greatest code. :\ Anyone have some ideas about how to fix it? Ive been up for 32 hours and im a bit fried. thanks for your help everyone... Converter AutoItV2toV3 [Version 1.0.6] (C) Copyright 2004 J-Paul Mesnage. V2.64 to V3.0.100 (Version 1.0.6) Successfull reading of config File : C:\Program Files\AutoIt3\Extras\v2_to_v3_Converter\AutoItV2toV3.dat ERROR at line : 79 Unsupported IF nesting : ExitPoint End of Conversion of C:\Program Files\AutoIt\Examples\English\batchDOC2RTF.aut (83 lines) Link to comment Share on other sites More sharing options...
MHz Posted July 3, 2006 Share Posted July 3, 2006 A rewrite is probably best.If you use the AutoIt3 Beta, then you maybe able to use a Word object to do this.Sample converted from here but could be changed to handle multiple files through a loop.Global $oWord, $sFile If Not $CMDLINE[0] Then MsgBox(0, "", "Usage: doc2txt.exe file.doc") Exit ElseIf $CMDLINE[0] > 1 Then Exit EndIf $sFile = $CMDLINE[1] $oWord = ObjCreate("Word.Application") $oWord.Documents.Open $sFile $oWord.Activedocument.SaveAs $sFile & ".rtf", 6 $oWord.Activedocument.Close $oWord = "" Link to comment Share on other sites More sharing options...
lukeneo Posted July 16, 2006 Share Posted July 16, 2006 A rewrite is probably best. If you use the AutoIt3 Beta, then you maybe able to use a Word object to do this. Sample converted from here but could be changed to handle multiple files through a loop. Global $oWord, $sFile If Not $CMDLINE[0] Then MsgBox(0, "", "Usage: doc2txt.exe file.doc") Exit ElseIf $CMDLINE[0] > 1 Then Exit EndIf $sFile = $CMDLINE[1] $oWord = ObjCreate("Word.Application") $oWord.Documents.Open $sFile $oWord.Activedocument.SaveAs $sFile & ".rtf", 6 $oWord.Activedocument.Close $oWord = "" I am getting errror messAGE LIKE THIS : The requested action with this object has failed ! Does any one resolved this my problem ? Please ... someone Answer if you have the answer ! BIG THANKS ! Link to comment Share on other sites More sharing options...
MHz Posted July 16, 2006 Share Posted July 16, 2006 I do not have Word installed so cannot debug the issue at the moment. Please supply more accurate error data if possible. This change may bring a better result hopefully. Added the loop as well. Just test with 1 file 1st. Global $oWord If Not $CMDLINE[0] Then MsgBox(0, "", "Usage: doc2txt.exe file.doc") Exit 1 EndIf $oWord = ObjCreate("Word.Application") If @error Then MsgBox(0x10, '', 'Object creation failed') Exit 2 Else For $i = 1 To $CMDLINE[0] If FileExists($CMDLINE[$i]) Then $oWord.Documents.Open($CMDLINE[$i]) $oWord.Activedocument.SaveAs($CMDLINE[$i] & ".rtf") $oWord.Activedocument.Close EndIf Next $oWord = "" EndIf Link to comment Share on other sites More sharing options...
lukeneo Posted July 16, 2006 Share Posted July 16, 2006 I do not have Word installed so cannot debug the issue at the moment. Please supply more accurate error data if possible. This change may bring a better result hopefully. Added the loop as well. Just test with 1 file 1st. Global $oWord If Not $CMDLINE[0] Then MsgBox(0, "", "Usage: doc2txt.exe file.doc") Exit 1 EndIf $oWord = ObjCreate("Word.Application") If @error Then MsgBox(0x10, '', 'Object creation failed') Exit 2 Else For $i = 1 To $CMDLINE[0] If FileExists($CMDLINE[$i]) Then $oWord.Documents.Open($CMDLINE[$i]) $oWord.Activedocument.SaveAs($CMDLINE[$i] & ".rtf") $oWord.Activedocument.Close EndIf Next $oWord = "" EndIf THE SAME ERROR MESSAGE AS ABOVE ...... THE ERROR DIALOG ..... $oWord.Documents.Open($CMDLINE[$i]) $oWord.Activedocument.SaveAs($CMDLINE[$i])^ERROR ERROR: The requested action with this object has failed ! I HAVE Link to comment Share on other sites More sharing options...
MHz Posted July 16, 2006 Share Posted July 16, 2006 So close, but still not sure of why you are having object error. If this does not work, then need a system to test with Word on it to figure out the issue . Hoping for a quote issue with this attempt may help solve . Global $oWord If Not $CMDLINE[0] Then MsgBox(0, "", "Usage: doc2txt.exe file.doc") Exit 1 EndIf $oWord = ObjCreate("Word.Application") If @error Then MsgBox(0x10, '', 'Object creation failed') Exit 2 Else For $i = 1 To $CMDLINE[0] If FileExists($CMDLINE[$i]) Then $oWord.Documents.Open('"' & $CMDLINE[$i] & '"') $oWord.Activedocument.SaveAs('"' & $CMDLINE[$i] & '.rtf"') $oWord.Activedocument.Close EndIf Next $oWord = "" EndIf Link to comment Share on other sites More sharing options...
MHz Posted July 17, 2006 Share Posted July 17, 2006 I was finally able to test the last code posted and it worked fine with Microsoft Word. The quotes may have been the issue. Opening the new files with WordPad worked OK to show that the SaveAs did as hoped with format change. The above code can be compiled and can just drag'n'drop the files onto the executable and the operation will happen. 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