pywin32

Getting last opened MS Word document object

隐身守侯 提交于 2019-12-01 10:09:31
问题 I have a python script called from a VBA AutoNew() sub in a MS Word 2003 template (.dot) - so it runs every time a document is created from this Word template. A third-party application creates documents from this template. There are a number of formatting issues with how the third-party application sets up the document, thus my script to tweak it once the third-party script has finished running. (I originally wrote the script in VBA, but problems with the VBA timer cause it to crash a

ImportError: DLL load failed when importing win32clipboard in application frozen with cx_Freeze

岁酱吖の 提交于 2019-12-01 09:11:29
I've got a Python 2.7 program that imports win32clipboard . I tried to freeze it with cx_Freeze 4.2.3 on Windows XP SP3 32-bit, to create an installation MSI. I made a setup.py according to the cx_Freeze documentation, and used the following command: c:\python27\python.exe setup.py bdist_msi When I run it on another PC that doesn't have Python 2.7 installed, I get an exception on the line that imports win32clipboard : ImportError: DLL load failed: The specified module could not be found. I can see that win32clipboard.pyd is being included in the build. What dependency is missing, and how can I

Why do I get different lists of open workbooks in Excel COM based on which IDE executes the code?

瘦欲@ 提交于 2019-12-01 08:54:15
import win32com.client as win32 excel = win32.gencache.EnsureDispatch('Excel.Application') for wb in excel.Workbooks: print(wb.Name) When I run this script using Sublime Text: A list of the names of open workbooks is printed. When I run this script using PyCharm: I get a blank list. Both are on the same PC and are using the same version of Python (3.5 32-bit). Not sure if this piece of info makes a difference, but I never ran the PyCharm installer when I first downloaded PyCharm. I downloaded the zip file and just run the PyCharm.exe from the unzipped folder every time. Could this be the

pywin32 / pywinauto not working properly in remote desktop when it is minimized

自作多情 提交于 2019-12-01 07:30:02
问题 I have a Jenkins pipeline that executes a program in a remote server that uses pywin to manipulate an application for functional tests. My application works great while I have the remote desktop oppened but when I close the remote desktop and run it from Jenkins, the app gets lost. What I do is to open the app and send an enter key. This is my app: os.startfile("C:\\Program Files (x86)\\SAP\\FrontEnd\\SAPgui\\saplogon.exe") time.sleep(5) handle = win32gui.FindWindow(0, "SAP Logon 740")

Why do I get different lists of open workbooks in Excel COM based on which IDE executes the code?

元气小坏坏 提交于 2019-12-01 05:53:23
问题 import win32com.client as win32 excel = win32.gencache.EnsureDispatch('Excel.Application') for wb in excel.Workbooks: print(wb.Name) When I run this script using Sublime Text: A list of the names of open workbooks is printed. When I run this script using PyCharm: I get a blank list. Both are on the same PC and are using the same version of Python (3.5 32-bit). Not sure if this piece of info makes a difference, but I never ran the PyCharm installer when I first downloaded PyCharm. I downloaded

Python Windows File Copy with Wildcard Support

瘦欲@ 提交于 2019-12-01 03:56:30
I've been doing this all the time: result = subprocess.call(['copy', '123*.xml', 'out_folder\\.', '/y']) if result == 0: do_something() else: do_something_else() Until today I started to look into pywin32 modules, then I saw functions like win32file.CopyFiles(), but then I found it may not support copying files to a directory. Maybe this functionality is hidden somewhere, but I haven't found it yet. I've also tried "glob" and "shutil" combination, but "glob" is incredibly slow if there are many files. So, how do you emulate this Windows command with Python? copy 123*.xml out_folder\. /y The

How to get the display names of multiple monitors with the Win32 API?

a 夏天 提交于 2019-12-01 03:23:37
问题 I have two monitors connected to my Windows PC -- one is a normal monitor and the other is a projector. Because Windows doesn't consistently assign one or the other as the primary monitor (in part because they aren't always both on when Windows boots), I need to programmatically detect which monitor is which. The Control Panel shows the names of the monitors as "HP 2159" (the normal monitor) and "PROJECTOR" in the screen where you choose which is the primary monitor. That's the information I

Update the TOC (table of content) of MS Word .docx documents with Python

半腔热情 提交于 2019-12-01 00:05:31
I use the python package "python-docx" to modify the structure amd content of MS word .docx documents. The package lacks the possibility to update the TOC (table of content) [ Python: Create a "Table Of Contents" with python-docx/lxml . Are there workarounds to update the TOC of a document? I thought about using "win32com.client" from the python package "pywin32" [ https://pypi.python.org/pypi/pypiwin32] or a comparable pypi package offering "cli control" capabilities for MS Office. I tried the following: I changed the document.docx to document.docm and implemented the following macro [ http:/

Multiple WindowsBaloonTip / TrayTip Notifications?

前提是你 提交于 2019-11-30 19:43:39
问题 If you were to use this code below to create TrayTips (BaloonTips) in the Notification Area you will notice that it only allows one message and then gets stuck and errors out. The code was taken from here: # -- coding: utf-8 -- from win32api import * from win32gui import * import win32con import sys, os import struct import time class WindowsBalloonTip: def __init__(self, title, msg): message_map = { win32con.WM_DESTROY: self.OnDestroy, } # Register the Window class. wc = WNDCLASS() hinst =

Update the TOC (table of content) of MS Word .docx documents with Python

馋奶兔 提交于 2019-11-30 18:06:11
问题 I use the python package "python-docx" to modify the structure amd content of MS word .docx documents. The package lacks the possibility to update the TOC (table of content) [Python: Create a "Table Of Contents" with python-docx/lxml. Are there workarounds to update the TOC of a document? I thought about using "win32com.client" from the python package "pywin32" [https://pypi.python.org/pypi/pypiwin32] or a comparable pypi package offering "cli control" capabilities for MS Office. I tried the