如何让python等待Excel宏/刷新完成 [英] How to have python wait until an Excel Macro/Refresh is done
本文介绍了如何让python等待Excel宏/刷新完成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用Python在excel中运行宏.我希望Python关闭Excel.宏会刷新excel中的数据连接,这可能会很慢.
I am using Python to run a macro in excel. and I want Python to close excel. The macro refreshes a data connection in excel which can be slow.
我如何让python等到刷新完成才能关闭.这就是我正在使用的,在xl.Quit之前需要一些东西,等到宏刷新完成后才能完成???
How do I have python wait until the refresh is done to close. This is what I am using, I need something before the xl.Quit that will wait until the refresh in macro is done????
import win32com.client
import os
xl = win32com.client.DispatchEx("Excel.Application")
wb = xl.workbooks.open("X:\Backoffice\Options Trading\BloombergRate.xlsm")
xl.Visible = True
xl.run("Refresh")
xl.Quit()
请问如何进行这项工作?
Wait ways can I make this work?
推荐答案
Edit your Refresh
macro to set QueryTable.BackgroundQuery
property to False
. This should cause the macro to block until it is done.
这篇关于如何让python等待Excel宏/刷新完成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文