Skip to content

Instantly share code, notes, and snippets.

@hybridjosto
Created April 20, 2014 10:00
Show Gist options
  • Save hybridjosto/11110204 to your computer and use it in GitHub Desktop.
Save hybridjosto/11110204 to your computer and use it in GitHub Desktop.
is excel open? if not open it!
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