MasterSetupMigration

Internal members (not exported)

Factory

Create #

Build a migration over the master setup workbook and its managers.

Signature:

Public Function Create(ByVal hostBook As Workbook, _
                       ByVal dropdowns As DropdownLists, _
                       ByVal variables As MasterSetupVariables, _
                       ByVal choices As LLChoices, _
                       ByVal translationsTable As ListObject, _
                       ByVal builder As DiseaseSheet, _
                       ByVal importService As MasterSetupImportService) As MasterSetupMigration

Parameters:

Returns: MasterSetupMigration ready to export or import.


Configuration

Initialise #

Attach the workbook and the managers the migration reads and writes through.

Signature:

Public Sub Initialise(ByVal hostBook As Workbook, _
                      ByVal dropdowns As DropdownLists, _
                      ByVal variables As MasterSetupVariables, _
                      ByVal choices As LLChoices, _
                      ByVal translationsTable As ListObject, _
                      ByVal builder As DiseaseSheet, _
                      ByVal importService As MasterSetupImportService)

Export

BuildMigrationWorkbook #

Build the migration workbook and answer it open.

Signature:

Public Function BuildMigrationWorkbook() As Workbook

The five sheets are written in order and take the export format DiseaseExporter gives a disease export. The workbook stays open and belongs to this class until ExportMigration saves it or the class is released.

Returns: Workbook. The migration workbook, open.


ExportMigration #

Write the migration workbook to disk and answer the saved path.

Signature:

Public Function ExportMigration(ByVal exportFolder As String) As String

Parameters:

Returns: String. The path of the saved file.


ReleaseWorkbook #

Close the migration workbook this class still holds, without saving.

Signature:

Public Sub ReleaseWorkbook()

Import

Import #

Read a migration file into the host workbook, which has to be empty.

Signature:

Public Sub Import(ByVal sourceBook As Workbook, Optional ByVal logger As DiseaseLogger = Nothing)

The file is checked first (its tag and its four sheets), then the target: a disease worksheet, a Variables line or a Choices line refuses the import with ProjectError.InvalidArgument naming what was found, and nothing is written. LastRefusal answers that name afterwards on either platform; Err.Description carries it on Windows only. The steps then run in the order each one feeds the next; the staging sheet of the disease blocks goes away on every path.

Parameters:


Results

LastRefusal #

Why the last import was refused, empty when it was not.

Signature:

Public Property Get LastRefusal() As String

Err.Description carries this too on Windows, and does NOT on Mac Excel, which replaces it as the error leaves the class. Read this rather than the description whenever the reason has to be shown or tested.

Returns: String. What the refusal found, or empty.


ImportedDiseases #

Names of the disease worksheets the last import built.

Signature:

Public Property Get ImportedDiseases() As BetterArray

ImportedDiseaseCount #

How many disease blocks the last import landed.

Signature:

Public Property Get ImportedDiseaseCount() As Long

AddedLanguages #

The language columns the last import added to the translations table.

Signature:

Public Property Get AddedLanguages() As BetterArray

Export Writers

CollectDiseaseSheets #

The disease worksheets of the host workbook, in sheet order.

Signature:

Private Function CollectDiseaseSheets() As Collection

WriteMetadata #

Write the label and value block of the Metadata sheet.

Signature:

Private Sub WriteMetadata(ByVal metadataSheet As Worksheet, ByVal diseaseCount As Long)

WriteWorkbookTags #

Tag the workbook as a migration file, with its disease count.

Signature:

Private Sub WriteWorkbookTags(ByVal targetBook As Workbook, ByVal diseaseCount As Long)

WriteDiseaseBlocks #

Write every disease block, the first at column 1, then one stride further each.

Signature:

Private Sub WriteDiseaseBlocks(ByVal diseasesSheet As Worksheet, ByVal diseaseSheets As Collection)

The writer keeps the next column itself. The UsedRange of an empty sheet is $A$1, so asking the sheet where it ends puts the first block at column 3.


WriteDiseaseBlock #

Write one disease block: the three tags, then the table as values.

Signature:

Private Sub WriteDiseaseBlock(ByVal diseasesSheet As Worksheet, _
                              ByVal diseaseWksh As Worksheet, _
                              ByVal startColumn As Long)

WriteBlock #

Copy a block of values to A1 of a sheet and wrap it in a plain table.

Signature:

Private Sub WriteBlock(ByVal targetSheet As Worksheet, ByVal sourceRange As Range, ByVal tableName As String)

MasterChoicesRange #

The master Choices block with its headers, as the master carries it.

Signature:

Private Function MasterChoicesRange() As Range

Import Checks

ValidateSource #

Refuse a source that is no migration file or lacks one of its sheets.

Signature:

Private Sub ValidateSource(ByVal sourceBook As Workbook)

RefuseFilledTarget #

Refuse a target that already carries data, naming what was found.

Signature:

Private Sub RefuseFilledTarget()

FirstDiseaseSheetName #

The first disease worksheet of the host workbook; empty with none.

Signature:

Private Function FirstDiseaseSheetName() As String

VariablesLineCount #

The lines of the Variables table carrying a variable name.

Signature:

Private Function VariablesLineCount() As Long

ChoicesLineCount #

The lines under the headers of the master Choices block.

Signature:

Private Function ChoicesLineCount() As Long

Import Steps

ImportTranslations #

The languages first, through SetupTranslationsTable, then the rows.

Signature:

Private Sub ImportTranslations(ByVal sourceBook As Workbook, ByVal logger As DiseaseLogger)

A language column the file carries and the target lacks is added through EnsureLanguages. The rows are then matched on their label: a row the target carries takes the language values of the file, a row it lacks is appended whole.


WriteTranslationRows #

Write the translation rows of the file onto the target table.

Signature:

Private Sub WriteTranslationRows(ByRef sourceBlock As Variant, ByVal logger As DiseaseLogger)

WriteLanguageCells #

Write the language cells of one source row on one target row.

Signature:

Private Sub WriteLanguageCells(ByRef sourceBlock As Variant, _
                               ByVal sourceRow As Long, _
                               ByVal targetRow As Long, _
                               ByVal columnIndexes As Collection)

ImportVariables #

The Variables table, through the manager, which matches by header.

Signature:

Private Sub ImportVariables(ByVal sourceBook As Workbook, ByVal logger As DiseaseLogger)

ImportChoices #

The Choices block, onto the headers the target already has.

Signature:

Private Sub ImportChoices(ByVal sourceBook As Workbook, ByVal logger As DiseaseLogger)

StretchChoicesTable #

Stretch the choices ListObject over the rows the import wrote under it.

Signature:

Private Sub StretchChoicesTable()

LLChoices writes the sheet and knows nothing of the table; the master event handlers read the sheet through the table.


RefreshDropdowns #

Rebuild the dropdowns, so the languages, the lists and the diseases exist.

Signature:

Private Sub RefreshDropdowns()

The preparation reads the languages off the translations table headers and the lists off the Choices sheet, which is why it runs after those two steps and before any disease sheet is built.


ImportDiseases #

Every Diseases block, in file order.

Signature:

Private Sub ImportDiseases(ByVal sourceBook As Workbook, ByVal logger As DiseaseLogger)

Row 1 is walked for the word Disease, so the blocks can sit at any stride and an empty gap between two blocks is passed over.


ImportOneBlock #

Stage one block on a hidden sheet and land it through the service.

Signature:

Private Sub ImportOneBlock(ByVal diseasesSheet As Worksheet, _
                           ByVal startColumn As Long, _
                           ByVal diseaseName As String, _
                           ByVal languageTag As String, _
                           ByVal logger As DiseaseLogger)

BuildStagingTable #

Copy one block into the staging sheet and answer its ListObject.

Signature:

Private Function BuildStagingTable(ByVal diseasesSheet As Worksheet, ByVal startColumn As Long) As ListObject

CountBlockRows #

Count the lines of a block, reading its variable name column.

Signature:

Private Function CountBlockRows(ByVal diseasesSheet As Worksheet, ByVal startColumn As Long) As Long

RemoveStagingSheet #

Drop the staging sheet when the host workbook carries one.

Signature:

Private Sub RemoveStagingSheet()

Lookups

IsDiseaseSheet #

A disease worksheet is known by its hidden sheetTag.

Signature:

Private Function IsDiseaseSheet(ByVal targetSheet As Worksheet) As Boolean

TagValue #

A workbook tag; a file with no hidden names store answers empty.

Signature:

Private Function TagValue(ByVal sourceBook As Workbook, ByVal nameId As String) As String

FindTable #

Find a ListObject by name anywhere in the workbook, then by sheet.

Signature:

Private Function FindTable(ByVal sourceBook As Workbook, _
                           ByVal tableName As String, _
                           ByVal sheetName As String) As ListObject

FindWorksheet #

Locate a worksheet by name without relying on implicit errors.

Signature:

Private Function FindWorksheet(ByVal targetBook As Workbook, ByVal sheetName As String) As Worksheet

EnsureWorksheet #

Ensure a worksheet exists, renaming the given template when there is one.

Signature:

Private Function EnsureWorksheet(ByVal targetBook As Workbook, _
                                 ByVal sheetName As String, _
                                 Optional ByVal template As Worksheet = Nothing) As Worksheet

LastUsedColumn #

The last used column of a sheet; 0 for a sheet holding nothing.

Signature:

Private Function LastUsedColumn(ByVal sheet As Worksheet) As Long

HeaderNames #

The header names of a ListObject, in column order.

Signature:

Private Function HeaderNames(ByVal table As ListObject) As BetterArray

BlockHeaders #

The header row of a block read with its headers.

Signature:

Private Function BlockHeaders(ByRef block As Variant) As BetterArray

JoinedLanguages #

The languages joined with the separator the Metadata sheet carries.

Signature:

Private Function JoinedLanguages(ByVal names As BetterArray) As String

LabelIndex #

Index of the labels of a translations block: label key to row.

Signature:

Private Function LabelIndex(ByRef block As Variant) As Collection

The first row of the block is the header row; a label found twice keeps its first row.


HeaderIndex #

Index of the headers of a block: header to column, without regard to case.

Signature:

Private Function HeaderIndex(ByRef block As Variant) As Collection

LookupRow #

The row of a label in the index, 0 when it is not there.

Signature:

Private Function LookupRow(ByVal keys As Collection, ByVal label As String) As Long

LookupColumn #

The column of a header in the index, 0 when it is not there.

Signature:

Private Function LookupColumn(ByVal keys As Collection, ByVal header As String) As Long

LabelKey #

A Collection key that carries the case of a label.

Signature:

Private Function LabelKey(ByVal label As String) As String

A Collection matches its keys without regard to case, and a translation label carries its case: "Hello" and "hello" are two labels. The key spells the capitalisation out beside the label, the way SetupTranslationsTable keys its own index.


ContainsKey #

Whether a name has already been seen, without regard to case.

Signature:

Private Function ContainsKey(ByVal keys As BetterArray, ByVal key As String) As Boolean

RangeBlock #

Read a range as a two-dimensional block, one cell included.

Signature:

Private Function RangeBlock(ByVal target As Range) As Variant

TextOf #

Text of a cell value; an error value or an empty cell reads as empty.

Signature:

Private Function TextOf(ByVal cellValue As Variant) As String

ResetTallies #

Start the tallies of a new import.

Signature:

Private Sub ResetTallies()

ErrorHandling

ThrowError #

Centralised error raising aligned with ProjectError codes.

Signature:

Private Sub ThrowError(ByVal errNumber As ProjectError, ByVal errMessage As String)

Refuse #

Refuse the import, keeping the reason readable after the raise.

Signature:

Private Sub Refuse(ByVal errMessage As String)

Mac Excel throws the description away as an error leaves a class method: the caller reads the number it was given and "Method 'Import' of object 'MasterSetupMigration' failed" in place of the message. Windows keeps the message. The reason is therefore held on the instance BEFORE the raise, and LastRefusal answers it on both platforms.

Parameters:

Throws:


Used in (3 file(s))