Moderators big_daddy Posted August 6, 2006 Moderators Share Posted August 6, 2006 (edited) There have been several requests for Microsoft Word Automation lately so I decided to take a stab at creating a library. DaleHohm has been kind enough to let me base my code off his IE.au3 library which will undoubtedly save countless hours. Currently it only has basic functions, but I will continue to add new functions and fix bugs as often as possible. Please test and provide as much feedback as possible, this will help keep me proactive with the project.Included in the beta version as of v3.2.3.9T1.0-1, 4/14/2007Word.au3Previous versions 1350+ downloads---Help File w/Examples (Updated for T1.0-1, 4/14/2007) - Thanks JdeBWord_Help_File.zipPrevious versions 620+ downloads---See http://www.autoitscript.com/fileman/users/Big_Daddy/libraries/word/history.htm for history. Edited April 26, 2007 by big_daddy Link to comment Share on other sites More sharing options...
randallc Posted August 6, 2006 Share Posted August 6, 2006 (edited) Great news. Funnily enough, I originally had planned to do this myself, but got caught up in the Excel stuff that people wanted, and ended up just using 4 funcs inside Excelcom to run Word Macros! I still use these a lot for that purpose; perhaps I can use yours early on if you get the runmacro going. expandcollapse popupFunc _WordCOM(ByRef $s_FilePath, $s_MEWordCom = "Macro", $s_Macro = "DestinationDirectory", $s_WordValue = "Hi", $s_i_Save = "NoSave", $s_i_Visible = "NotVisible", $s_i_Exit = "NotExit",$i_Suppress = 0) Local $o_Word If $s_i_Save = "Save" Then $s_i_Save = 1 If $s_i_Visible = "Visible" Then $s_i_Visible = 1 If $s_i_Exit = "Exit" Then $s_i_Exit = 1 ;MsgBox(0,"","$s_i_Visible="&$s_i_Visible) ;==================================================if all numbers If $s_i_Visible <> 1 Then $s_i_Visible = 0 If Not FileExists($s_FilePath) Or Not StringInStr($s_FilePath, "doc") Then _WordCreateBlank($s_FilePath) EndIf If Not IsObj ($o_Word) Then $o_Word = ObjGet ($s_FilePath) ; Get anWord Object from an existing filename If Not IsObj ($o_Word) Then Sleep(500) $o_Word = ObjGet ($s_FilePath) ; Get anWord Object from an existing filename If Not IsObj ($o_Word) Then MsgBox(0, "Word File Test", "Error: Could not open " & $s_FilePath & " as an Word Object.") EndIf EndIf EndIf If IsObj ($o_Word) Then With $o_Word Select Case StringInStr($s_MEWordCom, "Macro") .Application.Visible = $s_i_Visible $Close = 0 .Application.Run ($s_Macro) ;"Normal.NewMacros.Font4" Case StringInStr($s_MEWordCom, "Close") $Close = 1 EndSelect EndWith If $s_i_Save = 1 Then $o_Word.Save EndIf If $Close = 1 And $s_i_Exit = 0 Then ;$oWord.saved=1 $o_Word.close (0) EndIf If $s_i_Exit = 1 Then $o_Word.Application.Quit While ProcessExists('Winword.exe') Sleep(10) WEnd EndIf Else MsgBox(0, "Word File Test", "Error: Could not open " & $s_FilePath & " as an Word Object.") EndIf ;return $var EndFunc ;==>_WordCOM Func _WordMacro(ByRef $s_FilePath, $s_Macro = "DestinationDirectory", $s_WordValue = "Hi", $s_i_Visible = 0 ,$i_Suppress = 0) _WordCOM($s_FilePath, "Macro", $s_Macro, $s_WordValue, "NOTSave", $s_i_Visible , "NOTExit") EndFunc ;==>_WordMacro Func _WordClose(ByRef $s_FilePath, $s_i_Save = "NoSave", $s_i_Exit = "NotExit") _WordCOM($s_FilePath, "Close", "DestinationDirectory", "Hello", $s_i_Save, "NotVisible", $s_i_Exit) EndFunc ;==>_WordClose Func _WordCreateBlank($s_FilePath) $NewName = $s_FilePath $WordNew = ObjGet ($NewName) If IsObj ($WordNew) Then $WordNew.Application.quit $WordNew = ObjCreate ("Word.Application") $WordNew.documents.Add $WordNew.DisplayAlerts = 0 ;$WordNew.ScreenUpdating = 0 If FileExists($NewName) Then FileDelete($NewName) EndIf $WordNew.Activedocument.SaveAs ($NewName) $WordNew.DisplayAlerts = -1 ;$WordNew.ScreenUpdating = -1 $WordNew.quit EndFunc ;==>_WordCreateBlank Edited August 14, 2006 by randallc ExcelCOM... AccessCom.. Word2... FileListToArrayNew...SearchMiner... Regexps...SQL...Explorer...Array2D.. _GUIListView...array problem...APITailRW Link to comment Share on other sites More sharing options...
RazerM Posted August 6, 2006 Share Posted August 6, 2006 Looks good so far. Hope it goes well in future releases. My Programs:AInstall - Create a standalone installer for your programUnit Converter - Converts Length, Area, Volume, Weight, Temperature and Pressure to different unitsBinary Clock - Hours, minutes and seconds have 10 columns each to display timeAutoIt Editor - Code Editor with Syntax Highlighting.Laserix Editor & Player - Create, Edit and Play Laserix LevelsLyric Syncer - Create and use Synchronised Lyrics.Connect 4 - 2 Player Connect 4 Game (Local or Online!, Formatted Chat!!)MD5, SHA-1, SHA-256, Tiger and Whirlpool Hash Finder - Dictionary and Brute Force FindCool Text Client - Create Rendered ImageMy UDF's:GUI Enhance - Enhance your GUIs visually.IDEA File Encryption - Encrypt and decrypt files easily! File Rename - Rename files easilyRC4 Text Encryption - Encrypt text using the RC4 AlgorithmPrime Number - Check if a number is primeString Remove - remove lots of strings at onceProgress Bar - made easySound UDF - Play, Pause, Resume, Seek and Stop. Link to comment Share on other sites More sharing options...
i542 Posted August 6, 2006 Share Posted August 6, 2006 That's good script! i542 I can do signature me. Link to comment Share on other sites More sharing options...
JavaScript_Freek Posted August 6, 2006 Share Posted August 6, 2006 Tried opening with Beta. Nothing happened. [center]Cookyx.com :: Simple LAN Chat[/center] Link to comment Share on other sites More sharing options...
RazerM Posted August 6, 2006 Share Posted August 6, 2006 It's only a set of functions. You need to use them yourself My Programs:AInstall - Create a standalone installer for your programUnit Converter - Converts Length, Area, Volume, Weight, Temperature and Pressure to different unitsBinary Clock - Hours, minutes and seconds have 10 columns each to display timeAutoIt Editor - Code Editor with Syntax Highlighting.Laserix Editor & Player - Create, Edit and Play Laserix LevelsLyric Syncer - Create and use Synchronised Lyrics.Connect 4 - 2 Player Connect 4 Game (Local or Online!, Formatted Chat!!)MD5, SHA-1, SHA-256, Tiger and Whirlpool Hash Finder - Dictionary and Brute Force FindCool Text Client - Create Rendered ImageMy UDF's:GUI Enhance - Enhance your GUIs visually.IDEA File Encryption - Encrypt and decrypt files easily! File Rename - Rename files easilyRC4 Text Encryption - Encrypt text using the RC4 AlgorithmPrime Number - Check if a number is primeString Remove - remove lots of strings at onceProgress Bar - made easySound UDF - Play, Pause, Resume, Seek and Stop. Link to comment Share on other sites More sharing options...
GaryFrost Posted August 6, 2006 Share Posted August 6, 2006 You need to put examples so the noobs will somewhat understand. SciTE for AutoItDirections for Submitting Standard UDFs  Don't argue with an idiot; people watching may not be able to tell the difference.  Link to comment Share on other sites More sharing options...
Moderators big_daddy Posted August 7, 2006 Author Moderators Share Posted August 7, 2006 I made some small changes to the library which I felt were important enough for a new release, see update history for changes. I also added a basic example script to help the noobs (thanks gafrost).I'm open to suggestions on what functions should be included, please feel free to add your input. Here's a link that should give you an idea of what can be accomplished through scripting.Thanks,Bob Link to comment Share on other sites More sharing options...
Paulie Posted August 7, 2006 Share Posted August 7, 2006 I'm open to suggestions on what functions should be included, please feel free to add your input. Here's a link that should give you an idea of what can be accomplished through scripting.Thanks,BobWell, hate to state the obvious, but make it do everything on that link This is INCREDIBLE, very usefull, been looking for a 'word auto-mater' for like Months,thanks for the great UDFs Link to comment Share on other sites More sharing options...
Moderators big_daddy Posted August 9, 2006 Author Moderators Share Posted August 9, 2006 New update available! See update history for changes. Enjoy, Bob Link to comment Share on other sites More sharing options...
rbhkamal Posted August 9, 2006 Share Posted August 9, 2006 (edited) I know that your example doesn't do anything bad but McAfee VirusScan does this Edit:I removed the attachment to save space every time I run your example.Maybe you should use different ways to write this UDF.it is complaining about the _Quit, here is the "find out more":Edit:I removed the attachment to save space Edited December 11, 2006 by rbhkamal "When the power of love overcomes the love of power, the world will know peace"-Jimi Hendrix Link to comment Share on other sites More sharing options...
crystalburner Posted August 13, 2006 Share Posted August 13, 2006 I know that your example doesn't do anything bad but McAfee VirusScan does this every time I run your example. Maybe you should use different ways to write this UDF. it is complaining about the _Quit, here is the "find out more": can u print a word doc? Link to comment Share on other sites More sharing options...
Moderators big_daddy Posted August 13, 2006 Author Moderators Share Posted August 13, 2006 @rbhkamal - Application.Quit is the standard method for closing a word application object. I'm not sure why McAfee is picking up on it.@crystalburner - Of course. That will be one of the next functions I create, but I'm still trying to turn this into something user friendly. Link to comment Share on other sites More sharing options...
crystalburner Posted August 13, 2006 Share Posted August 13, 2006 @rbhkamal - Application.Quit is the standard method for closing a word application object. I'm not sure why McAfee is picking up on it.@crystalburner - Of course. That will be one of the next functions I create, but I'm still trying to turn this into something user friendly. shall i just use control send instead of waiting Link to comment Share on other sites More sharing options...
Moderators big_daddy Posted August 14, 2006 Author Moderators Share Posted August 14, 2006 shall i just use control send instead of waitingUntil I have the function finished you can try calling the method manually. Just call it from a document object using the link I provided as a reference. Here is what the syntax should look like, of course you need to change all the parameters to their corresponding values. $oDoc.PrintOut(Background, Append, Range, OutputFileName, From, To, Item, Copies, Pages, PageType, PrintToFile, Collate, ActivePrinterMacGX, ManualDuplexPrint, PrintZoomColumn, PrintZoomRow, PrintZoomPaperWidth, PrintZoomPaperHeight) Link to comment Share on other sites More sharing options...
DaleHohm Posted August 14, 2006 Share Posted August 14, 2006 Until I have the function finished you can try calling the method manually. Just call it from a document object using the link I provided as a reference. Here is what the syntax should look like, of course you need to change all the parameters to their corresponding values. $oDoc.PrintOut(Background, Append, Range, OutputFileName, From, To, Item, Copies, Pages, PageType, PrintToFile, Collate, ActivePrinterMacGX, ManualDuplexPrint, PrintZoomColumn, PrintZoomRow, PrintZoomPaperWidth, PrintZoomPaperHeight)Wouldn't $oDoc.PrintOut() alone work to print the entire document to the default printer? The printer config on my test machine is hosed at the moment so I can't test. Dale Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model Automate input type=file (Related) Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded Better Better? IE.au3 issues with Vista - Workarounds SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead? Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble Link to comment Share on other sites More sharing options...
vim Posted August 14, 2006 Share Posted August 14, 2006 Great job big_daddy! I used your example and my McAfee VirusScan didn't report any trouble at all. vim Link to comment Share on other sites More sharing options...
Moderators big_daddy Posted August 14, 2006 Author Moderators Share Posted August 14, 2006 @Dale - Thanks, your right this seems to work until I can complete the function. #include <Word.au3> $oWordApp = _WordCreate (@ScriptDir & "\Test.doc") $oDoc = $oWordApp.ActiveDocument $oDoc.Range.insertAfter ("This is some text to insert.") $oDoc.PrintOut () _WordQuit ($oWordApp, 0) Link to comment Share on other sites More sharing options...
crystalburner Posted August 14, 2006 Share Posted August 14, 2006 Until I have the function finished you can try calling the method manually. Just call it from a document object using the link I provided as a reference. Here is what the syntax should look like, of course you need to change all the parameters to their corresponding values. $oDoc.PrintOut(Background, Append, Range, OutputFileName, From, To, Item, Copies, Pages, PageType, PrintToFile, Collate, ActivePrinterMacGX, ManualDuplexPrint, PrintZoomColumn, PrintZoomRow, PrintZoomPaperWidth, PrintZoomPaperHeight) hmmm looks like hard work why wont this work ControlSend("test.doc - Microsoft Word", "", "_WwG1","^P") Link to comment Share on other sites More sharing options...
Moderators big_daddy Posted August 14, 2006 Author Moderators Share Posted August 14, 2006 hmmmlooks like hard workwhy wont this workControlSend("test.doc - Microsoft Word", "", "_WwG1","^P")Did you not see my post right before yours? I gave an example of how to print the entire document to the default printer. 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