How to call Excel VBA functions and subtitles using Python win32com?

My Excel workbook contains VBA submates and macros similar to the ones below; they are sitting in Module 1.

How to call them using python win32com?

Public Sub setA1(ByVal s As String) ThisWorkbook.ActiveSheet.Range("A1").Value = s End Sub Public Function getA1() As String getA1 = ThisWorkbook.ActiveSheet.Range("A1").Value End Function 

Thank you very much in advance!

+6
source share
1 answer
 import win32com.client xl=win32com.client.Dispatch("Excel.Application") xl.Workbooks.Open(Filename="c:\\temp\\book1.xls",ReadOnly=1) xl.Application.Run("setA1", '4') res = xl.Application.Run("getA1") print res xl = 0 

As simple as that ....

+9
source

All Articles