Is there a way to get VBA code to either save or export an Aspen Plus simulation session?
Yes - you can create VB or VBA code to save OR export Aspen Plus simulations.
SAVING SIMULATIONS:
To save a simulation, the code is as follows:
Call AspenPlusObject.SaveAs(YourFilePathName) where:AspenPlusObject is the name designated for the AspenPlus application in the VB main module YourFilePathName is a string variable containing the full path and filename, including file extension, of the file you wish to save. Valid file file extensions that you can use in the YourFilePathName string variable are: APW (Aspen Plus document file) BKP (backup file)APT (template file).
Call AspenPlusObject.SaveAs(YourFilePathName)
Valid file file extensions that you can use in the YourFilePathName string variable are:
APW (Aspen Plus document file) BKP (backup file)APT (template file).
Note: The file extension used in the YourFilePathName will determine what type of file is generated by Aspen Plus.
You can use the Excel/VBA file save function, GetSaveAsFileName, to prompt the user for a valid SaveAsfilename for saving:
YourFilePathName = application.Application.GetSaveAsFilename(lDefault_FileName, _ FileTypeFilter, Index, MessageForTitleBar)
where:Default_FileName is a string variable containing the default file name you would like displayed at the bottom of the SaveAs Dialogue FileTypeFilter is an integer that sets the default file type in the save as text box. For example, if the filter contained BKP, APW and APT filetypes then an Index=2 would make APW file types the default since APW is the second entry on the list.
For further discussions and infrastructure code, please see the attachment called CaseStudySaveAndExport.xls and its companion Aspen Plus model called Test.bkp. In the spreadsheet, go to the tools menu, click on Macro and then the VB Editor. In the VB session, find the subroutine called: cmd_SaveSimulation
EXPORTING:
Exporting files is a little more difficult - it requires a file name and a filetype arguement to complete the export. There are currently 10 types of files that can be exported:
The command to export is:
Call AspenPlusObject.Export(HAPEXP_xxxxx, YourFileName) where:HAPEXP_xxxxx is one of the constants used to pass an integer argument that defines the file type. For example, HAPEXP_BACKUP is a constant with a value of 1 that sets the export file type to a backup (*.bkp) file. See the end of this document for a list of the other constants
Call AspenPlusObject.Export(HAPEXP_xxxxx, YourFileName)
For example, to export an Report file called "MySimulation.rep", the command would be:
Call AspenPlusObject.Export(HAPEXP_REPORT, "MySimulation.rep")
-OR-
Call AspenPlusObject.Export(HAPEXP_REPORT, "MySimulation") where: HAPEXP_REPORT is the constant variable name to export a report (described in more detail at the end of this document) note:In the above example, the file extension in the second argument is optional
Call AspenPlusObject.Export(HAPEXP_REPORT, "MySimulation")
where: HAPEXP_REPORT is the constant variable name to export a report
(described in more detail at the end of this document)
Another example, to export both a Report (RUN1.rep) and an input file RUN1.inp), type the following:
Call AspenPlusObject.Export(HAPEXP_INPUT_REPORT, "RUN1") note: Do not supply a file extension for the second argument.
Call AspenPlusObject.Export(HAPEXP_INPUT_REPORT, "RUN1")
note: Do not supply a file extension for the second argument.
The first argument in the Export subroutine is an integer which designates the file type. The Aspen Plus object has constant variable names defined for each file type. You can use the Object Browser in VBA editor to see the complete list of options with a short description. Note however that some features have been sunset (e.g. export as DXF).
In the attached Excel spreadsheet, please see the subroutine called CBO_ExportType in the Sheet1 code, and also the subroutine called ExportMyFile in the Module 1 code.
VBExcel