Questions tagged [win32com]

win32com is a Python module to interact with Windows COM components. It is part of the Python for Win32 (pywin32) project by mhammond.

win32com is a Python module to interact with windows COM components. It is part of the Python for Win32 (pywin32) extensions project by mhammond, which provides access to many of the Windows APIs from Python.

The Python COM package can be used to interface to almost any COM program (such as the MS-Office suite), write servers that can be hosted by any COM client (such as Visual Basic or C++), and has even been used to provide the core ActiveX Scripting Support.

1868 questions
4
votes
1 answer

Write and execute excel VB macro with win32com.client

I am attempting to write a script that opens an existing .xlsx file, writes a Visual Basic macro script to auto-size comments, executes said macro, then closes and saves the workbook. I am quite unfamiliar with win32com.client, and after several…
Allan B
  • 329
  • 2
  • 9
4
votes
1 answer

Word & Python - Create Table of Contents

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…
Abraxas
  • 341
  • 1
  • 9
  • 28
4
votes
1 answer

Win32com Outlook Body Properties Error

While trying to retrieve the body of an outlook email message with the following code, I get com_error: (-2147467259, 'Unspecified error', None, None) Each of the print(message.) work, except the Body property import…
Marty
  • 41
  • 1
  • 2
4
votes
3 answers

Ask for admin access for a Python function in Windows

I want to copy a list of files to the Windows system directory (C:\Windows) using a Python function. I have a function: import shutil def copy_list(src_list, dst): for file in src_list: shutil.copy(file, dst) And I want to call it like…
lpsandaruwan
  • 790
  • 2
  • 11
  • 27
4
votes
5 answers

win32com Excel.Application can't open documents anymore

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 =…
Andy Do
  • 99
  • 1
  • 2
  • 14
4
votes
2 answers

How to insert a picture into Excel at a specified cell position with python (Anaconda) use vba

I try to use this link with vba code but in Python it doesn't work. import win32com.client Excel = win32com.client.Dispatch("Excel.Application") wb = Excel.Workbooks.Open(r'C:/Users/Home/Desktop/expdata.xlsx') wb.Worksheets("Report").Activate #…
Zzema
  • 197
  • 1
  • 2
  • 16
4
votes
1 answer

Python thread: The application called an interface that was marshalled for a different thread

The following code works without errors: self.sim.create_pnl_results(gui_values, dfs) This code gives me an error: thread = Thread(target=self.sim.create_pnl_results, args=(gui_values, dfs)) thread.start() in _ApplyTypes_…
Nickpick
  • 6,163
  • 16
  • 65
  • 116
4
votes
3 answers

Adding Excel Sheets to End of Workbook

I am trying to add excel worksheets to the end of a workbook, reserving the first sheet for a summary. import win32com.client Excel = win32com.client.DispatchEx('Excel.Application') Book = Excel.Workbooks.Add() Excel.Visible =…
PProteus
  • 549
  • 1
  • 10
  • 23
4
votes
1 answer

event handling of balloon tip with win32gui

I'm currently using a slightly modified version of the common example of the systemtray. #!/usr/bin/env python # Module : SysTrayIcon.py # Synopsis : Windows System tray icon. # Programmer : Simon Brunning - simon@brunningonline.net # Date …
4
votes
2 answers

Python code for running ms-Access Module Subroutine

I am very new to programming and this is my first question on stackoverflow. I am trying to make python open an .accdb file and run a subroutine which is already defined in Access. I manage to do it with Excel using this code: import…
4
votes
1 answer

Python win32com - Automating Word - How to replace text in a text box?

I'm trying to automate word to replace text in a word document using Python. (I'm on word 2003 if that matters and Python 2.4) The first part of my replace method below works on everything except text in text boxes. The text just doesn't get…
Greg
  • 45,306
  • 89
  • 231
  • 297
4
votes
1 answer

Win32com codes not working on IIS

I am trying to deploy a Python app on IIS webserver whenever there is a code that uses win32com objects is encoutered, it throws error, but the code is working fine on Python built-in webserver Here is the code: xlapp =…
4
votes
1 answer

How do I get a PID from a window title in windows OS using Python?

I need to feed a PID from a window that I know the title of. It's an installer program that seems to change vital credentials when the first "next" button is programmatically pressed in my code. I think it does this because the window fades away and…
Chris Stone
  • 129
  • 3
  • 15
4
votes
1 answer

Getting contact information from the Outlook GAL using Python and win32com

I am trying to write a script in Python that will pull the contact information from the Outlook Global Address List. For each entry, I've managed to get the name of the contact, as well as the alias (with some additional parsing). My code is posted…
Cameron
  • 43
  • 1
  • 4
4
votes
1 answer

Python 2.7 - win32com.client - Move a worksheet from one workbook to another

I'm trying to move one excel worksheet from workbook A to workbook B with python 2.7, but I keep getting an error. Python script: import…
Stephanie
  • 45
  • 1
  • 7