win32com

How to use win32com to handle overflow when querying Desktop Search?

◇◆丶佛笑我妖孽 提交于 2019-12-10 06:49:48
问题 I'm querying the Windows Desktop Search JET (ESE) database using Python + ADO. It works but after ~7600 records I get an exception when advancing to the next record using MoveNext . I know it is not at EOF because I can run the same query in VBScript and get way more records with the same query. Exception traceback Traceback (most recent call last): File "test_desktop_search.py", line 60, in <module> record_set.MoveNext() File "<COMObject ADODB.Recordset>", line 2, in MoveNext pywintypes.com

Send email to multiple recipients using win32com module in Python

折月煮酒 提交于 2019-12-10 02:48:36
问题 I am using win32com to send emails after my code is done. However, I cannot figure out how to send it to more than 1 person. Now I can only add myself in cc, but not in the recipient list. Here is my code: import win32com.client import datetime as date olMailItem = 0x0 obj = win32com.client.Dispatch("Outlook.Application") newMail = obj.CreateItem(olMailItem) newMail.Subject = 'Hi' newMail.Body = 'Hi' newMail.To = 'Amy' newMail.CC = 'Bob' newMail.Send() However if I try this: newMail.To = [

Python - Win32com - Open Workbook & Create a New Excel File for Each Tab

喜你入骨 提交于 2019-12-10 00:31:22
问题 I have an MS Excel Workbook that I would like to open and then loop through the tabs and create and save a workbook for each tab in the original workbook. So I open file A and there are tabs 1, 2, 3 and create and save a file B, C, D each with one a unique tab in it. I have the code for the VBA which creates a single copy of a worksheet but when I attempt to do this in Python I end up with all the tabs in each workbook. The following is the VBA that works: Sub ConvertTabsToFiles() Dim

Excel win32com programming with Python. Passing Parameters to function

江枫思渺然 提交于 2019-12-09 21:28:26
问题 I suspect there is an easy answer for this question but I can't find it anywhere! I am writing a function to plot a lot of data in excel and I am controlling the plotting with Python. I have generated all of the charts and each chart is its own sheet, but they are out of order. The VBA code for this is: Sheets("Chart1").Move After:=Sheets(3) This will take "Chart1" and move it after the 3rd sheet. How do I do this in Python? I know that the code is something along the lines of: xlChart.Move

Windows Application Automation with python/COM

怎甘沉沦 提交于 2019-12-08 08:21:37
问题 I'm trying to automate ChemDraw for a user in the background, preferably avoiding using SendKeys() as I believe that requires a ChemDraw instance to be visible for that to work. What I need to do is somehow click Edit -> Copy As -> InChI programmatically, then retrieve the result from the Windows clipboard. We're currently using Python and COM scripting to attempt this. Here's our current code: # Opens ChemDraw and loads the file, while keeping the window hidden. ChemDraw = w32.DispatchEx(

How to launch win32 applications in separate threads in Python

北城余情 提交于 2019-12-08 07:37:48
问题 So, I am having this following snippet which attempts to start Microsoft Powerpoint through the win32api: import threading import win32com.client import sys class myDemo(threading.Thread): def __init__(self): threading.Thread.__init__(self) def run(self): try: myObject = win32com.client.Dispatch("Powerpoint.Application") print "OK" except: print "Failed to start Powerpoint!" sys.exit(1) print "Now attempting to shutdown..." try: myObject.quit() except: print "Error" if __name__ == "__main__":

automate printing of existing MS Access report (preferably with Python, but open to alternatives)

二次信任 提交于 2019-12-08 07:05:01
问题 I have about 30 .accdb files, all contain a report with the same name. I'd like to automate saving the reports as PDFs for subsequent printing. That's all, no queries, no modification, just print the saved report to a PDF. I can open the db successfully, but I'm not sure how to do the rest. import win32com.client a = win32com.client.Dispatch("Access.Application") a.visible = 1 filename = r'C:\bla\Exam_1\PrintTest\db.accdb' db = a.OpenCurrentDatabase(filename) report_name = 'My_Report' a.Quit(

win32com Excel.Application can't open documents anymore

丶灬走出姿态 提交于 2019-12-08 07:00:50
问题 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()

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

Deadly 提交于 2019-12-08 04:46:23
问题 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

Python Printing from python32

自闭症网瘾萝莉.ら 提交于 2019-12-08 04:05:42
问题 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