Created
April 20, 2014 10:00
-
-
Save hybridjosto/11110204 to your computer and use it in GitHub Desktop.
is excel open? if not open it!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from win32com.client import Dispatch | |
import subprocess | |
import socket_client | |
def openExcel(workbook): | |
xl = Dispatch("Excel.Application") | |
xl.visible = True | |
wb = xl.Workbooks.Open(workbook) | |
def checkOpenApp(appname): | |
cmd = subprocess.Popen('tasklist', shell=True, stdout=subprocess.PIPE) | |
for line in cmd.stdout: | |
if appname in line: | |
return True | |
def isok(): | |
""" | |
Checks if Excel is open, if not opens relevant workbook | |
""" | |
wbk_to_open = 'C:\Users\B8694209\Desktop\uptime\client test.xlsb' | |
if not checkOpenApp('EXCEL.EXE'): | |
socket_client.sendMessage('Excel not open!') | |
openExcel(wbk_to_open) | |
isok() | |
else: | |
socket_client.sendMessage("Workbook open") | |
if __name__ == '__main__': | |
isok() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment