DW1 Posted June 11, 2008 Share Posted June 11, 2008 Hi all, I currently have a working script to add autotext entries into a template, but I am using a combination of a word macro and an autoit script. I believe that I can accomplish the same with just autoit, leaving no need for the word macro. Currently I have the following: Au3 #include <File.au3> #include <Word.au3> $template = FileOpenDialog( "Select *.doc template to modify", @ScriptDir, "Template (*.dot)", 3 ) $wordlist = FileOpenDialog( "Select *.txt text file containing words to add", @ScriptDir, "Text File (*.txt)", 3 ) $oWordApp = _WordCreate( $template, 0, 0 ) $eof = _FileCountLines( $wordlist ) If $eof < 1 Then Exit For $avar = 1 To $eof $ss = StringSplit( FileReadLine( $wordlist, $avar ), "|" ) _WordMacroRun( $oWordApp, "test", $ss[1], $ss[2]) Next _WordDocSave( $oWordApp ) _WordQuit( $oWordApp ) Macro Sub test(name As String, text As String) Selection.text = text Activedocument.AttachedTemplate.AutoTextEntries.Add name:=name, Range:=Selection _ .Range Selection.Delete End Sub Could somebody help me convert this to a pure autoit solution? AutoIt3 Online Help Link to comment Share on other sites More sharing options...
DW1 Posted June 11, 2008 Author Share Posted June 11, 2008 *BUMP* from page 3 AutoIt3 Online Help Link to comment Share on other sites More sharing options...
Moderators big_daddy Posted June 12, 2008 Moderators Share Posted June 12, 2008 See if this does what you need... #include <File.au3> #include <Word.au3> $template = FileOpenDialog("Select *.doc template to modify", @ScriptDir, "Template (*.dot)", 3) $wordlist = FileOpenDialog("Select *.txt text file containing words to add", @ScriptDir, "Text File (*.txt)", 3) $oWordApp = _WordCreate($template, 0, 0) $oDoc = _WordDocGetCollection($oWordApp, 0) $eof = _FileCountLines($wordlist) If $eof < 1 Then Exit For $avar = 1 To $eof $ss = StringSplit(FileReadLine($wordlist, $avar), "|") _WordDocAutoTextEntryAdd($oDoc, $ss[1], $ss[2]) Next _WordDocSave($oWordApp) _WordQuit($oWordApp) Func _WordDocAutoTextEntryAdd($o_Doc, $s_Name, $s_Text) $o_Doc.Application.Selection.text = $s_Text $o_Doc.AttachedTemplate.AutoTextEntries.Add($s_Name, $o_Doc.Application.Selection.Range) $o_Doc.Application.Selection.Delete EndFunc ;==>_WordDocAutoTextEntryAdd Link to comment Share on other sites More sharing options...
DW1 Posted June 12, 2008 Author Share Posted June 12, 2008 Awesome big_daddy, thank you... testing now... will inform of results AutoIt3 Online Help Link to comment Share on other sites More sharing options...
DW1 Posted June 12, 2008 Author Share Posted June 12, 2008 Works perfect, thanks again AutoIt3 Online Help Link to comment Share on other sites More sharing options...
Moderators big_daddy Posted June 12, 2008 Moderators Share Posted June 12, 2008 Works perfect, thanks again You're welcome! 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