JayFran Posted October 12, 2010 Posted October 12, 2010 I've been playing around with the code for a couple of days now, basically when the code is going to get the total # of docs from mailmerge then start printing. once its get to the "Microsoft Office Word" dialog to click ok to print as is, the script wont click ok... before it did after i added the rest of the code it wont... please help me out thanks. expandcollapse popup#include <Word.au3> Opt("WinTitleMatchMode", 2) Opt("WinDetectHiddenText", 1) Const $wdNextRecord = -2 Const $wdLastRecord = -5 Const $wdFirstRecord = 0 $handle = WinGetHandle("BuildSheetMergeALL.doc (Read-Only) - Microsoft Word", "") $oWord = _WordAttach($handle, "HWND") WinActivate($handle) ;$oIE = _IEAttach("BUILD INFORMATION", "text") Sleep(1000) $oWord.Activedocument.MailMerge.DataSource.ActiveRecord = $wdLastRecord ;Last record $lastRecord = $oWord.Activedocument.MailMerge.DataSource.ActiveRecord ;Store number of last record Sleep (500) $oWord.Activedocument.MailMerge.DataSource.ActiveRecord = $wdFirstRecord ;First record Sleep (500) For $i = 1 To $lastrecord $oDoc = _WordAttach("BUILD INFORMATION", "text") $oWordDoc = _WordDocGetCollection($oWord, 0) Do $try = _WordDocPrint($oWordDoc) $bp = WinGetHandle("Microsoft Office Word") WinWaitActive($bp) Sleep(550) ControlFocus("Microsoft Office Word", "&Yes", 6) ControlClick($bp, "&Yes", "[CLASS:Button; INSTANCE:1; ID:6; TEXT:&Yes]");<----------Right Here-----------> Sleep (500) ControlSend("[CLASS:Button; INSTANCE:1; ID:06; TEXT:&Yes]", "{Enter}") WinActive($handle) Sleep (500) ;To go to the next record $oWord.Activedocument.MailMerge.DataSource.ActiveRecord = $wdNextRecord ;Next record ;$oWordDoc = _WordDocGetCollection($oWord, 0) If $lastrecord = $lastrecord Then ExitLoop Until MsgBox(0, "TICKETS", "DONE!") Next
wakillon Posted October 12, 2010 Posted October 12, 2010 Try like this expandcollapse popup#include <Word.au3> Opt("WinTitleMatchMode", 2) Opt("WinDetectHiddenText", 1) Const $wdNextRecord = -2 Const $wdLastRecord = -5 Const $wdFirstRecord = 0 $handle = WinGetHandle("BuildSheetMergeALL.doc (Read-Only) - Microsoft Word", "") $oWord = _WordAttach($handle, "HWND") WinActivate($handle) ;$oIE = _IEAttach("BUILD INFORMATION", "text") Sleep(1000) $oWord.Activedocument.MailMerge.DataSource.ActiveRecord = $wdLastRecord ;Last record $lastRecord = $oWord.Activedocument.MailMerge.DataSource.ActiveRecord ;Store number of last record Sleep (500) $oWord.Activedocument.MailMerge.DataSource.ActiveRecord = $wdFirstRecord ;First record Sleep (500) For $i = 1 To $lastrecord $oDoc = _WordAttach("BUILD INFORMATION", "text") $oWordDoc = _WordDocGetCollection($oWord, 0) Do $try = _WordDocPrint($oWordDoc) $bp = WinGetHandle("Microsoft Office Word") WinActivate($bp) WinWaitActive($bp) Sleep(550) ControlFocus("Microsoft Office Word", "&Yes", 6) ;ControlClick($bp, "&Yes", "[CLASS:Button; INSTANCE:1; ID:6; TEXT:&Yes]");<----------Right Here-----------> ControlClick($bp, "&Yes", 'Button1' ) ;Sleep (500) ;ControlSend("[CLASS:Button; INSTANCE:1; ID:06; TEXT:&Yes]", "{Enter}") WinActivate($handle) Sleep (500) ;To go to the next record $oWord.Activedocument.MailMerge.DataSource.ActiveRecord = $wdNextRecord ;Next record ;$oWordDoc = _WordDocGetCollection($oWord, 0) If $lastrecord = $lastrecord Then ExitLoop Until MsgBox(0, "TICKETS", "DONE!") Next AutoIt 3.3.14.2 X86 - SciTE 3.6.0 - WIN 8.1 X64 - Other Example Scripts
JayFran Posted October 12, 2010 Author Posted October 12, 2010 Try like this expandcollapse popup#include <Word.au3> Opt("WinTitleMatchMode", 2) Opt("WinDetectHiddenText", 1) Const $wdNextRecord = -2 Const $wdLastRecord = -5 Const $wdFirstRecord = 0 $handle = WinGetHandle("BuildSheetMergeALL.doc (Read-Only) - Microsoft Word", "") $oWord = _WordAttach($handle, "HWND") WinActivate($handle) ;$oIE = _IEAttach("BUILD INFORMATION", "text") Sleep(1000) $oWord.Activedocument.MailMerge.DataSource.ActiveRecord = $wdLastRecord ;Last record $lastRecord = $oWord.Activedocument.MailMerge.DataSource.ActiveRecord ;Store number of last record Sleep (500) $oWord.Activedocument.MailMerge.DataSource.ActiveRecord = $wdFirstRecord ;First record Sleep (500) For $i = 1 To $lastrecord $oDoc = _WordAttach("BUILD INFORMATION", "text") $oWordDoc = _WordDocGetCollection($oWord, 0) Do $try = _WordDocPrint($oWordDoc) $bp = WinGetHandle("Microsoft Office Word") WinActivate($bp) WinWaitActive($bp) Sleep(550) ControlFocus("Microsoft Office Word", "&Yes", 6) ;ControlClick($bp, "&Yes", "[CLASS:Button; INSTANCE:1; ID:6; TEXT:&Yes]");<----------Right Here-----------> ControlClick($bp, "&Yes", 'Button1' ) ;Sleep (500) ;ControlSend("[CLASS:Button; INSTANCE:1; ID:06; TEXT:&Yes]", "{Enter}") WinActivate($handle) Sleep (500) ;To go to the next record $oWord.Activedocument.MailMerge.DataSource.ActiveRecord = $wdNextRecord ;Next record ;$oWordDoc = _WordDocGetCollection($oWord, 0) If $lastrecord = $lastrecord Then ExitLoop Until MsgBox(0, "TICKETS", "DONE!") Next Unfortunatley that did not work. It stalls at the same place mines does... the funny thing is that if it I were to take out all the could and leave just the portion where it clicks "YES" then it will work. when its altogether it will stall...
wakillon Posted October 12, 2010 Posted October 12, 2010 (edited) Unfortunatley that did not work. It stalls at the same place mines does... the funny thing is that if it I were to take out all the could and leave just the portion where it clicks "YES" then it will work. when its altogether it will stall...try with ControlClick ( $bp, "", "&Yes" ) Edited October 12, 2010 by wakillon AutoIt 3.3.14.2 X86 - SciTE 3.6.0 - WIN 8.1 X64 - Other Example Scripts
MrMitchell Posted October 13, 2010 Posted October 13, 2010 You could also just try fixing the margins, if the changes are minute enough? I suggested this in your other post, not sure if you saw it?Also, you could add these constants:Const $wdAlertsNone = 0Const $wdAlertsAll = -1Then before printing, use this line to suppress the alert message:$oWord.DisplayAlerts = $wdAlertsNoneThen your print line:$try = _WordDocPrint($oWordDoc)Then re-enable the alers:$oWord.DisplayAlerts = $wdAlertsAll
JayFran Posted October 13, 2010 Author Posted October 13, 2010 You could also just try fixing the margins, if the changes are minute enough? I suggested this in your other post, not sure if you saw it?Also, you could add these constants:Const $wdAlertsNone = 0Const $wdAlertsAll = -1Then before printing, use this line to suppress the alert message:$oWord.DisplayAlerts = $wdAlertsNoneThen your print line:$try = _WordDocPrint($oWordDoc)Then re-enable the alers:$oWord.DisplayAlerts = $wdAlertsAllBRILLIANT!!! Thanks Alot! How can I learn more about the add-ons after the variables. for example the $oWord.Activedocument.MailMerger.... I just think thats all that!
MrMitchell Posted October 13, 2010 Posted October 13, 2010 Open Word. ALT+F11 to open Microsoft Visual Basic Editor. F2 to then open up Object Browser. Some stuff is hidden but you can find lots of Methods, Properties, constants, etc... Also, if you can't find something by searching, just record a macro, then go back and look at the macro's code to get the method's name and how to use it.
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