6. July 2026

File Management Workflows

Your task is to run 100 simulations, save results in a file in specifically named folders next to the database file. Instead of dealing with manually creating folders and files and copying data from the parameter workbook like a caveman you are sure: with INOSIM, there must be a way to automate this – and there is!

In this tip & trick, we show you how to get the path to the database file, create a folder, write the content of a table object into a CSV file and an Excel Workbook and save them at a specific path. And to complete the file management workflow, we cover how to remove a file.

Find a model export including all functions in the downloads. If you are looking for a way to run multiple simulation runs in a row, check out this tip & trick.

Getting the folder path of the database and selecting the output folder

The following function returns the folder path of the database file (.imdf) that is open in this instance of INOSIM. Using this path, it is possible to set the path of the output folder and output files into that folder.

Public Function RootDatabase() As String

    Dim splitConnectionString() As String
    Dim splitPath() As String
    Dim fullPath As String
    Dim fileName As String
    Dim fileRoot As String

    splitConnectionString = Split(ConnectionString,"""")
    fullPath = splitConnectionString(1)
    splitPath = Split(fullPath,"\")
    fileName = splitPath(UBound(splitPath))
    fileRoot = Left(fullPath,Len(fullPath) - Len(fileName) - 1) ' 1 for \
     
    RootDatabase = fileRoot

End Function

The folder path of the database can be accessed, and the output folder appended to the folder path of the database as follows:

Public RootPath As String
RootPath = RootDatabase()

Public FolderPath As String
FolderPath = RootPath & "\Output Files"

Outputting a table object as a CSV-file

The following function outputs a table object as comma separated values. It takes these items as input:

  • VBA_Table: The table object to be written to a comma separated file.
  • TableName: The name of the table object.
  • FullFilePath: FolderPath & “\Table.csv”
  • Overwrite: Selecting true will overwrite the file, selecting false will append to the file.
  • ri, ci: Selecting true respectively will write the row index or column index. Selecting false will not write the row or column index.
  • SeparatorTag: Chooses the separator tag, default is “;”. This input is optional.
  • CommentTag: Chooses the comment tag, default is “<!–”. This input is optional. Comments are not part of standard .csv-files but a custom modification that has proven useful for our uses.
Public Function Table2CSV_Output(VBA_Table As Table, TableName As String, FullFilePath As String, Overwrite As Boolean, ci As Boolean, ri As Boolean, Optional SeparatorTag As String = "", Optional CommentTag As String = "")
' Write table object to csv-file
 
'   VBA_Table       = Table Object
'   TableName       = Section Name e.g. "Resources"
'   FullFilePath    = complete path incl. file name
'   Overwrite       = Overwrite existing data In file(True/False) (Select False To Append)
'   ri, ci          = write row index, column index, true/false
'   SeparatorTag    = Optional, Default ";"
'   CommentTag      = Optional, Default "----"    'replace with comment tag given in text
 
    If SeparatorTag = "" Then SeparatorTag = ";"
    If CommentTag = "" Then CommentTag = "----"    'replace with comment tag given in text
 
    Dim OutString  As String
    Dim Separator  As String
    Dim fHandle    As Integer
 
    FullFilePath = Trim(FullFilePath)
 
    fHandle = FreeFile
    If Overwrite Then
        FileOpen fHandle, FullFilePath, OpenMode.Output
    Else
        FileOpen fHandle, FullFilePath, OpenMode.Append
    End If
    'Print #fHandle, vbUTF8BOM;              'write file in UTF-8 coding
 
    ' write comment line
    Print fHandle, CommentTag & " Table: " & TableName
 
    Dim row As Long, col As Long    'internal
    Dim rs As Long, cs As Long      'row/column start (0/1) (write first row/first column as table index)
    If ci And VBA_Table.ColumnIndex Then 
        rs = 0      ' Export w column index (row 0)
    ElseIf ci = False And VBA_Table.ColumnIndex = False Then
        rs = 1      ' Export w/o column index (row 0)
    Else
        Stop        ' table does not have a column index
    End If
 
    If ri And VBA_Table.RowIndex Then
        cs = 0
    ElseIf ri = False And VBA_Table.RowIndex = False Then
        cs = 1
    Else
        Stop        ' table does not have a row index
    End If
 
    If VBA_Table.RowCount > 0 Then
        For row = rs To VBA_Table.RowCount
            OutString = ""
            Separator = ""
            For col = cs To VBA_Table.ColumnCount
                OutString = OutString & Separator & VBA_Table(row,col)
                Separator = ";"
            Next
 
            PrintLine fHandle, OutString
 
        Next
    End If
 
    FileClose fHandle
 
End Function

Outputting a table object as an Excel Workbook

The function below outputs a table object as an Excel Workbook with Workbook XML Extension in INOSIM 2026. It takes these items as input:

  • VBA_Table: The table object to be written to a workbook
  • FullFilePath: FolderPath & “\Table.xlsx”
  • TableName: The name of the table object

Note that this function automatically writes the row and column index of the table object by default. Feel free to adapt the function for your use case.

Public Function Table2WorkbookXML_Output(VBA_Table As Table, FullFilePath As String, TableName As String)
    Dim wb As Workbook = New Workbook
    wb.Worksheets.Add TableName

    Dim row As Integer
    Dim col As Integer

    For row = 0 To VBA_Table.RowCount
        For col = 0 To VBA_Table.ColumnCount
            wb.Worksheets(TableName).CellYX(row + 1, col + 1).Value = VBA_Table(row, col)
        Next
    Next

    wb.SaveToFile(FullFilePath)
    
End Function

Deleting a file using WWB

The function below deletes a file using its predefined path. It takes the following as input:

  • FullFilePath: FolderPath & “\Table.xlsx”
    • This will specify the path to “Table.xlsx” and the function will delete the file.

Attention: this function will delete the file without further questions. Risk of data loss!

Public Function DeleteFile(FullFilePath As String)
    If Dir(FullFilePath) <> "" Then
        Kill FullFilePath
    End If
End Function

More Questions?

Want to know more about this topic or have another question? Please contact us!

Array ( [posts_per_page] => 3 [post_type] => [category__in] => Array ( [0] => 36 ) [orderby] => rand [order] => ASC )

More Tips & Tricks

In this tip, you learn how to create PDFs which display a selected time range of a complex Gantt chart. You also learn how to…

26. November 2020

Fast Sorting Of Arrays

Fast Sorting Of Arrays When sorting arrays, the runtime of the applied sorting procedure may play a crucial role. For smaller amounts of data, that…

19. July 2021

Custom Gantt Colors

The INOSIM Gantt chart provides the option to color allocation bars on the basis of various predefined attributes. In the order view, it is possible…

more

Direct Contact

During local business hours

Germany +49 231 97 00 250