Jump to content

ControlClick not clicking issue


JayFran
 Share

Recommended Posts

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.

#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
Link to comment
Share on other sites

Try like this

#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.0WIN 8.1 X64 - Other Example Scripts

Link to comment
Share on other sites

Try like this

#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...
Link to comment
Share on other sites

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 by wakillon

AutoIt 3.3.14.2 X86 - SciTE 3.6.0WIN 8.1 X64 - Other Example Scripts

Link to comment
Share on other sites

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 = 0

Const $wdAlertsAll = -1

Then before printing, use this line to suppress the alert message:

$oWord.DisplayAlerts = $wdAlertsNone

Then your print line:

$try = _WordDocPrint($oWordDoc)

Then re-enable the alers:

$oWord.DisplayAlerts = $wdAlertsAll

Link to comment
Share on other sites

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 = 0

Const $wdAlertsAll = -1

Then before printing, use this line to suppress the alert message:

$oWord.DisplayAlerts = $wdAlertsNone

Then your print line:

$try = _WordDocPrint($oWordDoc)

Then re-enable the alers:

$oWord.DisplayAlerts = $wdAlertsAll

BRILLIANT!!! 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!

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...