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

win32com.client.Dispatch works but not win32com.client.gencache.EnsureDispatch

i'm learning win32com for python and I've got a strange problem. I'e trying to export Outlook Contacts in a List of Dictionnary. My code works perfectly with win32com.client.Dispatch("Outlook.Application). But it returns 0 contacts with…
franckgaga
  • 81
  • 1
  • 1
  • 7
4
votes
4 answers

Retrieving outlook Contacts via python win32com

I am Trying to get Contacts out of Outlook using Python. The code is : import win32com.client import pywintypes o = win32com.client.Dispatch("Outlook.Application") ns = o.GetNamespace("MAPI") profile = ns.Folders.Item("Outlook") contacts =…
Nagri
  • 3,008
  • 5
  • 34
  • 63
4
votes
2 answers

Python - run Excel macro

I would like to use Python to run a macro contained in MacroBook.xlsm on a worksheet in Data.csv. Normally in excel, I have both files open and shift focus to the Data.csv file and run the macro from MacroBook. The python script downloads the…
user1137778
  • 1,111
  • 3
  • 14
  • 26
3
votes
1 answer

How to use win32com module in Jython

I have some codes of python that convers word file to html file, it uses win32com module, like this from win32com import client as wc I hoped to invoke python program in java codes, so I used Jython. But Jython don't recognition win32com module,…
RonQi
  • 1,247
  • 2
  • 8
  • 9
3
votes
1 answer

python ppt find and replace within a chart

I already referred these posts here here, here and here. Please don't mark it as a duplicate. I have a chart embedded inside the ppt like below I wish to replace the axis headers from FY2021 HC to FY1918 HC. Similarly, FY2122 HC should be replaced…
The Great
  • 7,215
  • 7
  • 40
  • 128
3
votes
1 answer

How to paste an Excel chart into PowerPoint placeholder using Python?

I have an excel file with a series of formatted charts on a tab called Charts. I have named the charts, Figure1, Figure2, Figure3, etc. I have an existing PowerPoint template. The template has 2 placeholders per slide (so that it can accommodate 2…
brb
  • 1,123
  • 17
  • 40
3
votes
1 answer

Accessing a specific instance of Enterprise Architect via COM from Python

A running instance of EA can be accessed from a Python script with something like: from win32com import client eaApp = client.GetActiveObject("EA.App") eaRepo = eaApp.Repository However, this seems to always returns the COM object of the instance…
3
votes
0 answers

Confirm if email was sent - win32com.client

outlook = win32.Dispatch('outlook.application') mail = outlook.CreateItem(0) mail.SentOnBehalfOfName = 'EMAIL' mail.To = 'EMAIL' mail.Subject = 'Message subject' mail.Body = 'Message body' mail.HTMLBody = 'HTML Message body' #this field is…
gaurav2141
  • 130
  • 8
3
votes
1 answer

Delphi Win32 TXMLDocument can't be instantiated and used from a thread?

I've been working with an Indy TIdTCPServer object and instantiating a TXMLDocument object instance during the TIdTCPServer.OnExecute event. I find it quite surprising that I get an exception when xml.Active is set to true: Microsoft MSXML is not…
X-Ray
  • 2,816
  • 1
  • 37
  • 66
3
votes
1 answer

Calling Excel macros/Excel Solver from Python over com

I have a macro inside a 2007 xlsm file that, when called, creates a solver configuration (target, constraints, ...) and performs the solve without any user interaction. When run manually from Excel, this works fine. I now want to script this from…
dgorissen
  • 6,207
  • 3
  • 43
  • 52
3
votes
1 answer

Excel prompts "Name cannot be the same as built-in name" when opened by win32com but not when opened by me manually

I'm trying to automate some things with python, one of the steps is opening the .xlsx file using the "win32com.client" module and then printing a few sheets into PDF. It all works fine if I have the file already opened in Excel, but if the Python…
Agen
  • 63
  • 5
3
votes
1 answer

Why can't Python set the Excel print area on a VM without open RDP connection?

I'm trying to use win32com to print an Excel sheet. This works fine if I have a remote desktop connection the VM this is running on, but if I'm disconnected, the task fails. I've hit two related errors: 1) With the print area set in…
Jamie Bull
  • 12,889
  • 15
  • 77
  • 116
3
votes
2 answers

How do I run excel using all the default add-ins from Python win32com

import win32com import win32com.client as win32 xl = win32.gencache.EnsureDisplatch('Excel.Application') This fires up Excel, but for whatever reason none of the plugins load. If Excel was already loaded, the plugins will stay loaded and be…
Jason Goldstein
  • 1,117
  • 2
  • 11
  • 20
3
votes
4 answers

Python Win32, how to save an XLS as a CSV?

I'm loading up a .xlsx with win32com and would like to save the results as a csv when I'm done. myworkbook.SaveAs('results.csv') gives me an xlsx file with a csv extension. How do I save as an actual CSV?
Jason Goldstein
  • 1,117
  • 2
  • 11
  • 20
3
votes
1 answer

win32com python unusual behaviour

New to win32com. Below is my code for converting xlsx file to webpage and capturing the range of cells as .png. The problem I am facing is that some times the code run fine but sometimes it throws errors. import os import sys import…