(RPA study) using multiple threads running click VBA message box

Comprehensive arts tournament flag RPA free download
Download
http://www.i-search.com.cn/index.html?from=line27

Business scene
after use win32com running Excel macros operation (VBA), will encounter VBA run the final step in a message box will pop up, need to click the message box, VBA to run over, so go join Try components after running VBA when you click is not clickable, so consider using multiple threads to achieve.

Process Code
Import ubpa.iautomation AS iautomation
Import Threading
Import PythonCOM
Import Time
# Click the message box button
DEF cilck_ok ():
the while True:

Try abnormal

    try:
        # 鼠标点击
        iautomation.WinSearchDepth=2
        selectorJson = {"selector":[{"ControlType":"按钮","ControlTypeID":"0xC350","Index":"1"},
    {"ControlType":"对话框","ControlTypeID":"0xC370","Index":"1"}]}
        iautomation.do_click(win_class=r'XLMAIN',win_name=r'aaaa.xlsm - Excel',selector=selectorJson,button=r'left',curson=r'center',offsetX=0,offsetY=0,times=1,run_mode=r'unctrl',waitfor=3)
        time.sleep(1)
        # Break中断
        break
    except Exception as e:

        pass
    finally:
        pass

#VBA run code
DEF run_vba (path):
'' '
Be sure to add pythoncom.CoInitialize ()
Be sure to add pythoncom.CoInitialize ()
Be sure to add pythoncom.CoInitialize ()
important things to say three times
' ''
#CoInitialize is Windows API functions provided, used to tell Windows to create a single-threaded manner com objects
pythoncom.CoInitialize ()
# load Excel
xlApp = win32com.client.Dispatch ( "Excel.Application")
# set whether to open Excel
xlApp.Visible = True
# set whether to display warnings and message boxes

Guess you like

Origin blog.51cto.com/14253212/2402651