win32com

Call was rejected by callee in win32com if a dialog box is open or excel is otherwise waiting for the user

不羁岁月 提交于 2019-12-08 02:18:37
问题 I need to determine if Excel is ready to accept a COM object from win32com in Python. For instance if a dialog box is open in excel, any call to a win32com function will cause a 'Call was rejected by callee' error. Through trial and error I have found that if Excel ( actaully I assume any Office product ) has a dialog box open, any call to win32com will result in an error. After quite a bit of googling I have found many questions about what amounts to self inflicted dialog boxes being open. i

Call MS Access module function from Python after compiling with py2exe fails

。_饼干妹妹 提交于 2019-12-08 01:56:56
问题 I have been running the python code below for approx a year now. But am about to move onto a new job. In order to make things easy for the department I am leaving, I want to compile this code into a .exe file. I have tried compiling against Python 2.5 and 2.7 with the same results. But when when running the exe file I get the following error H:\development\DMS_Import_Data\dist>import_data.exe Run Live or Development Import (L = Live, D = Dev, X = Exit):l 5:3:2012 10:56 Opening Live Database..

How to wait until Excel calculates formulas before continuing with win32com

こ雲淡風輕ζ 提交于 2019-12-07 19:09:35
问题 I have a win32com Python script that combines multiple Excel files into a spreadsheet and saves it as a PDF. How it works now is that the output is almost all #NAME? because the file is output before the Excel file's contents are calculated (which may take up to a minute). How I force the workbook to calculate the values and wait until its done before continuing? excel = win32.Dispatch('Excel.Application') # moving stuff to this spreadsheet wb1 = excel.Workbooks.Open(filepath1) ws1 = excel

Installing the pypiwin32 module

这一生的挚爱 提交于 2019-12-07 18:02:02
问题 I get this error when I run a program: --------------------------------------------------------------------------- ModuleNotFoundError Traceback (most recent call last) <ipython-input-10-b045b37982bc> in <module>() 4 #speech recognition 5 import speech_recognition as sr ----> 6 import win32com.client 7 import comtypes.client 8 #speech synthesis ModuleNotFoundError: No module named 'win32com' --------------------------------------------------- When I tried to install the pypiwin32 module, I

Python Printing from python32

六眼飞鱼酱① 提交于 2019-12-07 12:35:32
I can't get Python to print a word doc. What I am trying to do is to open the Word document, print it and close it. I can open Word and the Word document: import win32com.client msword = win32com.client.Dispatch("Word.Application") msword.Documents.Open("X:\Backoffice\Adam\checklist.docx") msword.visible= True I have tried next to print msword.activedocument.printout("X:\Backoffice\Adam\checklist.docx") I get the error of "print out not valid". Could someone shed some light on this how I can print this file from Python. I think it might be as simple as changing the word "printout". Thanks, I'm

Word & Python - Create Table of Contents

拈花ヽ惹草 提交于 2019-12-07 08:39:26
问题 I'm using the pywin32.client extension for python and building a Word document. I have tried a pretty good host of methods to generate a ToC but all have failed. I think what I want to do is call the ActiveDocument object and create one with something like this example from the MSDN page: Set myRange = ActiveDocument.Range(Start:=0, End:=0) ActiveDocument.TablesOfContents.Add Range:=myRange, _ UseFields:=False, UseHeadingStyles:=True, _ LowerHeadingLevel:=3, _ UpperHeadingLevel:=1 Except in

Create new Access database and tables using Python

放肆的年华 提交于 2019-12-07 07:20:50
问题 I'm trying to create an Access database in Python and add two new tables to it. I'm using win32com and have managed to create the database but can't create the tables. All I get is unhelpful Windows errors. Can anyone help me? The following code works fine: dbname = r'C:/Users/Guest/Desktop/NewDB.mdb' db = Dispatch("Access.Application") dbEngine = db.DBEngine workspace = dbEngine.Workspaces(0) dbLangGeneral = ';LANGID=0x0409;CP=1252;COUNTRY=0' newdb = workspace.CreateDatabase(dbname,

win32com Excel.Application can't open documents anymore

南笙酒味 提交于 2019-12-06 16:02:21
This was working last week but for some reason it stopped working today, maybe because of the new year? def remove_strikethroughs(xlsx): excel = win32com.client.Dispatch('Excel.Application') xl = pd.ExcelFile(xlsx) sheet_names = xl.sheet_names for sheet in sheet_names: if any(tab in sheet for tab in tabs_used): #print (sheet) wb = excel.Workbooks.Open(xlsx) ws = wb.WorkSheets(sheet) for cell in ws.Range('A5:B150'): if cell.Font.Strikethrough == True: cell.value = '[MDU]' + str(cell) wb.Save() wb.Close() excel.Visible = True excel.DisplayAlerts = True excel.Application.Quit() I get the

Python: How to search all file types for a text string

纵然是瞬间 提交于 2019-12-06 15:20:15
I'm trying to write a program which will be able to search all files (both the file names and their contents) in a user-specified directory for a particular string, and then move these files to a new user-specified directory. EDIT: Ok, so I've made a few changes to my code. The way it now works is: a list of files is obtained using os.path.walk(). Then, each file in the list is searched for the string specified by the user. First only the file names are checked for the string, and any positive matches are moved to a separate list. Then we start to look inside the files, using the file

Send Email From Specific Outlook Account Via Python?

≡放荡痞女 提交于 2019-12-06 14:01:20
问题 I had some code that was written to email lab users whenever certain processes had finished running. This was sent from a gmail account, using SMTP. However, my supervisor wants the mail to be sent from an official department address, which means that I have use Outlook and MAPI. I've had an account created which I want the email to originate from regardless of the lab machine the job is being run on. The problem is that I can only get email to send from the local Outlook account, and not all