Dear Experts,
I want to call the VBA Excel functions with optional parameters like Range.PasteSpecial(...) for example in PowerScript functions.
I tried the following:
OLEObject lole_WS_From // Excel worksheet
OLEObject lole_WS_To // Excel worksheet
(...)
lole_WS_From.Rows("1:3").Copy // works
lole_WS_To.Rows("1:3").PasteSpecial(-4163, -4142, False, False) // results in
// "Error calling external object function pastespecial"
Is it possible to call VBA Excel functions with optional parameters?
If it's possible: How is the syntax?
Thanks in advance for all trials to help me!
Kind regards,
Konrad Kaltenbach
Dear Mark,
thanks a lot for your elaborate and comprehensive answers and your additional thoughts!
On your question: I wanted Excel stay "passive" and hidden until the table is filled. But probably no problems will appear when the window is activated as you showed me.
Regarding your thoughts:
You're right: I didn't publish the complete code of the function where PasteSpecial is called but only an extract which I assumed to be complete with respect to the OLE objects and your queries.
"myoleobject1.WorkBooks[2].WorkSheets[1].Rows("1:3").PasteSpecial(-4163, -4142, False, False)" I will try next week. Thanks! But, yes, probably activating the window will not cause any problems.
Grateful regards,
Konrad
following your suggestion I tried the following:
xlsInstanz.Application.Workbooks[li_WBk].Worksheets[li_WS].Rows("1:3").PasteSpecial(-4163, -4142, false, false )
(cf. my source code posted Tuesday, 30 March 2021 09:05 AM UTC and the comment). The error still occurred (as long as the window is not activated before).
A workbook opened with "xlsInstanz.Application.Workbooks.Open(ls_file)"
after having started Excel with
"li_err = lole_Excel.ConnectToNewObject( "excel.application" )"
instead can apparently not be manipulated programmatically (with function calls like
"lole_WB.Worksheets(idx).Name = ls_ws_from" or
"lole_WS_To.Rows("1:3").PasteSpecial(-4163, -4142, False, False)" for example).