win32com

COM error in downloading attachment from outlook through win32com

℡╲_俬逩灬. 提交于 2019-12-24 10:45:58
问题 import win32com.client import os outlook = win32com.client.Dispatch("Outlook.Application").GetNamespace("MAPI") inbox = outlook.GetDefaultFolder(6) messages = inbox.Items message = messages.GetFirst() attachments = message.Attachments for i in messages: if(i.UnRead==True): attachment = attachments.Item(1) attachment.SaveASFile(os.getcwd() + '\\' + str(attachment)) else: pass I am getting below error when trying to download the attachment from outlook Error: com_error: (-2147352567, 'Exception

How to emulate press and hold with pywin32

别说谁变了你拦得住时间么 提交于 2019-12-24 09:26:52
问题 I am trying to write a python script to send a press and hold key signal. Right now all I have managed to do is the following: import win32com.client shell = win32com.client.Dispatch("Wscript.Shell") shell.SendKeys("z") However, this only sends an instantaneous key pressed event. What I would like to do is a key down and key up, something along the lines of: shell.SendKeys("z{down}") time.sleep(.25) shell.SendKeys("z{up}") But I cannot find any documented way to achieve this. EDIT: I also

How to have python wait until an Excel Macro/Refresh is done

自闭症网瘾萝莉.ら 提交于 2019-12-24 09:16:07
问题 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. 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 =

Read only Excel Cells with values python win32com

て烟熏妆下的殇ゞ 提交于 2019-12-24 07:15:18
问题 I have an Excel Document like the following num value1 value2 1 A 100 2 B 3 c 300 I want to iterate through value2 for something with a value of over 200, and if it finds a value over 200, print value1 . The big thing I'm having an issue with is telling it to stop the for loop once it reaches the end of the cells with text in it. My loop would ideally be something like this: while columnA is not empty: if value2 > 200: print (value1) a few notes: I'm using win32com. ColumnA will never be

How to pass arguments to win32com event handler

自闭症网瘾萝莉.ら 提交于 2019-12-24 03:41:34
问题 The code below works fine. I can't find a way to pass some arguments to EventHandler or to call methods of MainClass from EventHandler . For example instead of using constant param , I'd like to pass it through constructor or setter method. I've tried recommendations from here. But in this case EventHandler instance does not catch any events (or at least nothing appears in stdout). class EventHandler: param = "value" def OnConnected(self): print 'connected' return True class MainClass: def

How to use win32com.client.constants with MS Word?

空扰寡人 提交于 2019-12-23 16:15:51
问题 Whats wrong with this code? Why win32com.client.constants doesn't have attribute wdWindowStateMinimize? >>> import win32com.client >>> w=win32com.client.Dispatch("Word.Application") >>> w.WindowState = win32com.client.constants.wdWindowStateMinimize Traceback (most recent call last): File "<pyshell#2>", line 1, in <module> w.WindowState = win32com.client.constants.wdWindowStateMinimize File "C:\Python34\lib\site-packages\win32com\client\__init__.py", line 170, in __getattr__ raise

Registered COM object not recognized by python's win32com.client.dispatch()

无人久伴 提交于 2019-12-23 13:07:03
问题 I'm trying to load a COM object with Python. I'm using win32com.client.Dispatch("Name.Of.Object") to load it, and the COM object has been registered with regsvr32 and appears as an entry in my registry in both HKLM/CLSID and HKLM/Wow6432Node/CLSID. I can open it using VBScript just fine, but Python's win32com.client.Dispatch() gives me this error: Traceback (most recent call last): File "<stdin>", line 1, in <module> File "C:\Python27\lib\site-packages\win32com\client\__init__.py", line 95,

Python, Pyinstaller creating shortcuts in windows

心不动则不痛 提交于 2019-12-23 12:43:42
问题 I am making a python script that creates a shortcut ( .lnk ) file, using win32com.client module, I am using pyinstaller to convert it to exe. I'm also using Tkinter , so I need --tk support in pyinstaller . Pyinstaller doesn't seem to work with --tk and import win32com.client at the same time (I have no idea why) I need this to work. Maybe there's a way to create shortcuts without win32com.client (I've searched a lot without success) or to make pyinstaller work (I foud an issue between

Create Excel Hyperlinks in Python

末鹿安然 提交于 2019-12-23 05:52:20
问题 I am using win32com to modify an Excel spreadsheet (Both read and edit at the same time) I know there are other modules out there that can do one or the other but for the application I am doing I need it read and processed at the same time. The final step is to create some hyperlinks off of a path name. Here is an Example of what I have so far: import win32com.client excel = r'I:\Custom_Scripts\Personal\Hyperlinks\HyperlinkTest.xlsx' xlApp = win32com.client.Dispatch("Excel.Application")

Python save xlPicture from clipboard

梦想的初衷 提交于 2019-12-23 04:01:04
问题 Currently I have an xlPicture saved in my clipboard from the call (via win32com): ws.Range(ws.Cells(1,1),ws.Cells(8+rows,total_length)).CopyPicture() #Copies xlPicture to clipboard Now I want to save the image in my clipboard to a file, so I tried using PIL: from PIL import ImageGrab img = ImageGrab.grabclipboard() img.save(os.path.join(r'C:\Windows\Temp\WS_Template_Images','test.png'),'PNG') But ImageGrab.grabclipboard() returns None, I assume xlPicture is somehow not a compatible type for