如何用Progress 4GL实现Excel活动工作表复制到工作簿末尾
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

