Jump to content



Photo

Microsoft Word Automation Library


  • Please log in to reply
116 replies to this topic

#1 big_daddy

big_daddy

  • Moderators
  • 2,499 posts

Posted 06 August 2006 - 05:56 AM

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.9

T1.0-1, 4/14/2007

Attached File  Word.au3   85.97K   4477 downloadsPrevious versions 1350+ downloads

---

Help File w/Examples (Updated for T1.0-1, 4/14/2007) - Thanks JdeB

Attached File  Word_Help_File.zip   47.83K   2597 downloadsPrevious versions 620+ downloads

---

See http://www.autoitscript.com/fileman/users/Big_Daddy/libraries/word/history.htm for history.

Edited by big_daddy, 26 April 2007 - 05:37 PM.

BD Scripting - My scripting repository.AutoIt Menu - Firefox extension with several links and tools for the AutoIt Forums!AutoIt Snippets Database - Store and share all your favorite snippets here! Welcome to AutoIt 1-2-3 - Great starting place for newcomers.Learning to Script with AutoIt - Another good starting place for newcomers.SciTE - The best AutoIt Script Editor. Posted Image







#2 randallc

randallc

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 1,902 posts

Posted 06 August 2006 - 06:18 AM

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.

AutoIt         
Func _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 by randallc, 14 August 2006 - 10:32 PM.


#3 RazerM

RazerM

    cowinkeedenky - coincidence?

  • Active Members
  • PipPipPipPipPipPip
  • 1,246 posts

Posted 06 August 2006 - 10:46 AM

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.

#4 i542

i542

    Captain on the Bridge.

  • Active Members
  • PipPipPipPipPipPip
  • 1,821 posts

Posted 06 August 2006 - 02:37 PM

That's good script!
i542
I can do signature me.

#5 JavaScript_Freek

JavaScript_Freek

    Oldie but never advanced.

  • Active Members
  • PipPipPipPipPipPip
  • 318 posts

Posted 06 August 2006 - 05:18 PM

Tried opening with Beta. Nothing happened.

#6 RazerM

RazerM

    cowinkeedenky - coincidence?

  • Active Members
  • PipPipPipPipPipPip
  • 1,246 posts

Posted 06 August 2006 - 06:21 PM

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.

#7 GaryFrost

GaryFrost

    I don't need your attitude. I have one of my own

  • Developers
  • 7,854 posts

Posted 06 August 2006 - 06:58 PM

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.


#8 big_daddy

big_daddy

  • Moderators
  • 2,499 posts

Posted 07 August 2006 - 04:19 AM

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
BD Scripting - My scripting repository.AutoIt Menu - Firefox extension with several links and tools for the AutoIt Forums!AutoIt Snippets Database - Store and share all your favorite snippets here! Welcome to AutoIt 1-2-3 - Great starting place for newcomers.Learning to Script with AutoIt - Another good starting place for newcomers.SciTE - The best AutoIt Script Editor. Posted Image

#9 Paulie

Paulie

    Waiting for Misaki Nakahara

  • Active Members
  • PipPipPipPipPipPip
  • 5,103 posts

Posted 07 August 2006 - 04:23 AM

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

Well, hate to state the obvious, but make it do everything on that link :whistle:

This is INCREDIBLE, very usefull, been looking for a 'word auto-mater' for like Months,

thanks for the great UDFs
I'm still looking for my heart song.

Posted Image


#10 big_daddy

big_daddy

  • Moderators
  • 2,499 posts

Posted 09 August 2006 - 01:03 AM

New update available! See update history for changes.

Enjoy,
Bob
BD Scripting - My scripting repository.AutoIt Menu - Firefox extension with several links and tools for the AutoIt Forums!AutoIt Snippets Database - Store and share all your favorite snippets here! Welcome to AutoIt 1-2-3 - Great starting place for newcomers.Learning to Script with AutoIt - Another good starting place for newcomers.SciTE - The best AutoIt Script Editor. Posted Image

#11 rbhkamal

rbhkamal

    I just can't leave this forum!!!!!

  • Active Members
  • PipPipPipPipPipPip
  • 503 posts

Posted 09 August 2006 - 01:38 AM

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 by rbhkamal, 11 December 2006 - 09:42 PM.

"When the power of love overcomes the love of power, the world will know peace"-Jimi Hendrix

#12 crystalburner

crystalburner

    Adventurer

  • Active Members
  • PipPip
  • 144 posts

Posted 13 August 2006 - 09:22 PM

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?

#13 big_daddy

big_daddy

  • Moderators
  • 2,499 posts

Posted 13 August 2006 - 09:56 PM

@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. :whistle:
BD Scripting - My scripting repository.AutoIt Menu - Firefox extension with several links and tools for the AutoIt Forums!AutoIt Snippets Database - Store and share all your favorite snippets here! Welcome to AutoIt 1-2-3 - Great starting place for newcomers.Learning to Script with AutoIt - Another good starting place for newcomers.SciTE - The best AutoIt Script Editor. Posted Image

#14 crystalburner

crystalburner

    Adventurer

  • Active Members
  • PipPip
  • 144 posts

Posted 13 August 2006 - 10:02 PM

@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. :whistle:



shall i just use control send instead of waiting

#15 big_daddy

big_daddy

  • Moderators
  • 2,499 posts

Posted 14 August 2006 - 03:56 AM

shall i just use control send instead of waiting

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)

BD Scripting - My scripting repository.AutoIt Menu - Firefox extension with several links and tools for the AutoIt Forums!AutoIt Snippets Database - Store and share all your favorite snippets here! Welcome to AutoIt 1-2-3 - Great starting place for newcomers.Learning to Script with AutoIt - Another good starting place for newcomers.SciTE - The best AutoIt Script Editor. Posted Image

#16 DaleHohm

DaleHohm

    Think of IE as an API...

  • MVPs
  • 5,889 posts

Posted 14 August 2006 - 04:38 AM

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
IE.au3 issues with Vista - Workarounds, Automate input type=file (Related)SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=YFree Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curlMSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model,Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbeddedFind and harvest Enum constants for COM codeAutoIt Snippets Database - you too can contribute!Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your troubleDoesn'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?

#17 vim

vim

    Polymath

  • Active Members
  • PipPipPipPip
  • 218 posts

Posted 14 August 2006 - 05:03 AM

Great job big_daddy!
I used your example and my McAfee VirusScan didn't report any trouble at all.
vim

#18 big_daddy

big_daddy

  • Moderators
  • 2,499 posts

Posted 14 August 2006 - 05:49 PM

@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)

BD Scripting - My scripting repository.AutoIt Menu - Firefox extension with several links and tools for the AutoIt Forums!AutoIt Snippets Database - Store and share all your favorite snippets here! Welcome to AutoIt 1-2-3 - Great starting place for newcomers.Learning to Script with AutoIt - Another good starting place for newcomers.SciTE - The best AutoIt Script Editor. Posted Image

#19 crystalburner

crystalburner

    Adventurer

  • Active Members
  • PipPip
  • 144 posts

Posted 14 August 2006 - 07:39 PM

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")

#20 big_daddy

big_daddy

  • Moderators
  • 2,499 posts

Posted 14 August 2006 - 07:57 PM

hmmm

looks like hard work

why wont this work

ControlSend("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.
BD Scripting - My scripting repository.AutoIt Menu - Firefox extension with several links and tools for the AutoIt Forums!AutoIt Snippets Database - Store and share all your favorite snippets here! Welcome to AutoIt 1-2-3 - Great starting place for newcomers.Learning to Script with AutoIt - Another good starting place for newcomers.SciTE - The best AutoIt Script Editor. Posted Image




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users