1

In native visual basic within Excel, the expected behavior is

Dim AvayaReport As Object
Dim AvayaServer As Object
...
...
Set ReportInfo = AvayaServer.Reports.Reports("<Report Name>")
AvayaServer.Reports.CreateReport ReportInfo, AvayaReport

After the last line, the CreateReport method mutates AvayaReport to be a report object in this library. However, when I replicate this code within Python, AvayaReport does not get mutated.

import win32com.client
...
AvayaReport = win32com.client.dispatch("ACSREP.cvsReport")
...

ReportInfo = AvayaServer.Reports.Reports(r'<Report Name>")
AvayaServer.Reports.CreateReport(ReportInfo, AvayaReport)

I have tried to compare the behavior between the two environments and with the exception of this issue, the surrounding code is working as intended. However, this COM object has this weird implementation where it requires an empty object to be passed into it's arguments and it changes that object to reflect the created report, but I cannot figure out a way to make this work within Python.

Within VBA, the CreateReport definition is as follows:

Function CreateReport(oRepInfo, oReport, [sTimeZone as String = "default"]) As Boolean

Member of ACSTLG.cvsCatalog

Green8Ball
  • 23
  • 3
  • In the VBA code, how is the `AvayaReport` object created? Or is it uninitialized? Why do you explicitly create this object in Python? How is the `AvayaServer` object created? I think I can see what the issue will be, but need a bit more information. – DS_London Feb 20 '23 at 17:19
  • In VBA, `AvayaReport` is created with the `Dim AvayaReport as Object` line. It is otherwise uninitialized, only declared. However, I could also have early binding set up, and initialize it as `Dim AvayaReport as New ACSREP.cvsReport` and it would have no change in whether this code works or not – Green8Ball Feb 21 '23 at 19:10
  • 1
    Unlike VBA, Python doesn't pass parameters by reference, only by value. Hence a copy is made of the variable passed. As I understand it, `win32com` handles these [in,out] parameters is by returning the out parameter from the function. Depending what the server is expecting you might get away with `AvayaReport = AvayaServer.Reports.CreateReport(ReportInfo, None)`. Otherwise take a look at this link: http://timgolden.me.uk/pywin32-docs/html/com/win32com/HTML/variant.html and pass a `VARIANT(pythoncom.VT_DISPATCH,None)` parameter instead of `None`. – DS_London Feb 21 '23 at 22:36

0 Answers0