You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何用Progress 4GL实现Excel活动工作表复制到工作簿末尾

How to Copy an Excel Worksheet to the End of a Workbook in Progress 4GL

Got it, let's fix this for you! The issue here is that Progress 4GL handles COM method parameters a bit differently than VBA. Your existing code is almost there, but the way you're passing the After parameter to the Copy method isn't right for Progress syntax.

Correct Progress 4GL Code

Here's the adjusted version of your code that matches the functionality of your VBA snippet:

DEFINE VARIABLE chExcelApplication AS COM-HANDLE. /* com-handle for the application */
DEFINE VARIABLE chWorkbook AS COM-HANDLE. /* com-handle for the workbook */
DEFINE VARIABLE iSheetCount AS INTEGER. /* variable to track the current sheet count */

CREATE "Excel.Application" chExcelApplication.
chWorkbook = chExcelApplication:Workbooks:Open("C:\tmp\test.xlsx").
iSheetCount = chWorkbook:sheets:COUNT.

/* Use named parameter to specify the "After" target (matches VBA's After:=) */
chWorkbook:Sheets(1):COPY(INPUT After = chWorkbook:Sheets(iSheetCount)).

/* Optional: Save changes, clean up COM objects */
chWorkbook:SAVE().
chWorkbook:CLOSE().
chExcelApplication:QUIT().
RELEASE OBJECT chWorkbook.
RELEASE OBJECT chExcelApplication.

Why Your Original Code Didn't Work

In VBA, Sheets(1).Copy After:=Sheets(Sheets.Count) uses a named parameter (After:=) to tell Excel where to place the copied sheet. But in Progress 4GL, you can't use the :after = ... syntax directly after the method call. Instead, you need to pass the After parameter into the COPY method itself, either by name (like in the example above) or by position:

/* Alternative: Pass parameters by position (first = Before, second = After) */
chWorkbook:Sheets(1):COPY(INPUT , INPUT chWorkbook:Sheets(iSheetCount)).

Since we don't need to specify the Before parameter, we just leave that first spot empty with INPUT ,.

Key Difference from VBA

VBA allows you to skip leading optional parameters and use named parameters to target the ones you need. Progress 4GL supports this too, but requires the INPUT ParameterName = Value syntax when calling COM methods.

内容的提问来源于stack exchange,提问作者Newbie

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.08 11:12:48