- Konrad Kaltenbach
- PowerBuilder
- Monday, 10 May 2021 09:18 AM UTC
Dear Experts,
I want to call VisualBasic for Application (VBA) macros and functions in Word or Excel documents which I have written myself out of/from PowerScript functions (instead of rewritting them in the PowerScript functions).
Is this possible?
If it is: How is the syntax?
Assume, I have an Excel file with a macro Macro1() and a function Fct1(ByVal Something As String) As Integer in Module1 of its VBAProject and a PowerScript function containing the following lines:
"String ls_FileWithMacro
OLEObject xlsInstanz
ls_FileWithMacro = ... // Full name of the Excel file
xlsInstanz = CREATE OLEObject
xlsInstanz.connecttoobject( ls_FileWithMacro )"
How could I call Macro1 and/or Fct1 afterwards?
Thanks in advance for all trials to help me.
Kind regards,
Konrad Kaltenbach
Before calling functions and subroutines (like SaveAs e. g.) provided by VBA you have to activate the window with the office application first*. And if you want to call your own stuff this is sufficient, too:
lole_Win = xlsInstanz.Application.Windows(ls_nameOfExcelFile)
lole_Win.Activate
// Now the following calls are successful without exception:
xlsInstanz.Application.Run("Makro1") //
xlsInstanz.application.run("Modul1.Makro1") //
xlsInstanz.application.run("Makro3", "line1: Greetings from", "line2: PowerScript") //
xlsInstanz.application.run("Modul1.Makro3", "line1", "line2") //
ll = long(xlsInstanz.application.run("Makro2", "line1: Waiting for", "line2: an integer")) //
messagebox("ll: " , String(ll))
*https://community.appeon.com/index.php/qna/q-a/how-calling-vba-excel-functions-with-optional-arguments
Find Questions by Tag
Helpful?
If a reply or comment is helpful for you, please don’t hesitate to click the Helpful button. This action is further confirmation of their invaluable contribution to the Appeon Community.