SetupImportService
Orchestrates setup workbook synchronisation: validating, importing, exporting, and cleaning setup worksheets (Dictionary, Choices, Exports, Analysis, Translations). Supports both table-level import via CustomTable and domain-class-driven import via dedicated managers (LLdictionary, LLChoices, LLExport, Analysis, SetupTranslationsTable). Guards Excel state through ApplicationState and protects/unprotects worksheets via IPasswords.
Factory helpers
create #
Create a ready-to-use service instance
Signature:
Public Function Create(ByVal importPath As String, Optional ByVal progressDisplay As Object) As ISetupImportService
Validates the import path and optional progress display, creates a new SetupImportService instance, assigns the path and display, and returns the configured interface reference.
Parameters:
importPath: String. Path to the source setup workbook.progressDisplay: Optional Object. UI element receiving textual updates (must expose Caption or Value).
Returns: ISetupImportService. Configured service instance.
Public configuration
path #
Retrieve configured import path.
Signature:
Public Property Get Path() As String
Returns: String. The configured import path.
progress-object #
Retrieve the progress display object.
Signature:
Public Property Get ProgressObject() As Object
Returns: Object. The progress display object.
display-prompts #
Retrieve the display prompts toggle.
Signature:
Public Property Get DisplayPrompts() As Boolean
Returns: Boolean. True when prompts are enabled.
set-export-folder #
Provide an explicit folder for exports, bypassing the folder picker.
Signature:
Public Sub SetExportFolder(ByVal folderPath As String)
Parameters:
folderPath: String. The folder path to use for exports.
last-export-file #
Path of the last export produced by the service.
Signature:
Public Property Get LastExportFile() As String
Returns the full file path of the last export workbook saved by the service. Returns an empty string when no export has occurred.
Returns: String. The last export file path, or empty.
Core workflow
check #
Validate the requested import operation before execution.
Signature:
Public Sub Check(ByVal importDictionary As Boolean, _
ByVal importChoices As Boolean, _
ByVal importExports As Boolean, _
ByVal importAnalysis As Boolean, _
ByVal importTranslations As Boolean, _
Optional ByVal cleanSetup As Boolean = False)
Ensures at least one import option is selected, verifies the import path is configured and the file exists, then attempts to open and immediately close the source workbook to confirm it is readable.
Parameters:
importDictionary: Boolean. Flag requesting dictionary import.importChoices: Boolean. Flag requesting choices import.importExports: Boolean. Flag requesting exports import.importAnalysis: Boolean. Flag requesting analysis import.importTranslations: Boolean. Flag requesting translations import.cleanSetup: Optional Boolean. When True, performs a clean-only run. Defaults to False.
Throws:
- ProjectError.InvalidArgument When no import option is selected.
- ProjectError.SomethingWentWrong When the source workbook cannot be opened.
clean #
Clean target worksheets ahead of a fresh import.
Signature:
Public Sub Clean(ByVal pass As IPasswords, ByVal sheetsList As BetterArray)
Iterates over the requested sheets, unprotects each one, clears all ListObject data and worksheet comments, then re-protects.
Parameters:
pass: IPasswords. Password handler for worksheet protection.sheetsList: BetterArray. Worksheets participating in the clean-up.
import #
Perform the setup import from the configured workbook into the host workbook.
Signature:
Public Sub Import(ByVal pass As IPasswords, ByVal sheetsList As BetterArray)
Opens the source workbook, iterates over each requested sheet, matches ListObjects between source and host, and delegates import to CustomTable.Import. Handles sheet protection/unprotection and export column alignment via PrepareImport.
Parameters:
pass: IPasswords. Password handler for worksheet protection.sheetsList: BetterArray. Worksheets participating in the import.
Workbook-driven import
import-from-workbook #
Perform the setup import leveraging dedicated worksheet classes.
Signature:
Public Sub ImportFromWorkbook(ByVal pass As IPasswords, Optional ByVal sheetsList As BetterArray = Nothing)
Uses domain-specific classes (LLdictionary, LLChoices, LLExport, Analysis, SetupTranslationsTable) to import each worksheet from the source workbook. Falls back to the default sheets list when none is provided.
Parameters:
pass: IPasswords. Password handler for worksheet protection.sheetsList: Optional BetterArray. Worksheets to import. Defaults to all five setup sheets.
Workbook driven Export
export-to-workbook #
Export all setup worksheets to a new workbook.
Signature:
Private Sub Export(Optional Byval outwb As Workbook)
Creates or reuses an export workbook, then exports each setup worksheet (Dictionary, Choices, Exports, Analysis, Translations) using domain-specific managers, along with hidden names and formatting data.
Parameters:
outwb: Optional Workbook. Pre-existing target workbook. When Nothing, creates a new one.
Internal members (not exported)
State and constants
initialize #
Set default state on construction.
Signature:
Private Sub Class_Initialize()
Public configuration
path-set #
Store the path to the setup workbook.
Signature:
Public Property Let Path(ByVal value As String)
Parameters:
value: String. The path to assign.
progress-object-set #
Store the progress display object reference.
Signature:
Public Property Set ProgressObject(ByVal value As Object)
Parameters:
value: Object. The progress display to store.
self #
Current object instance cast to the interface.
Signature:
Public Property Get Self() As ISetupImportService
Returns: ISetupImportService. The current instance.
display-prompts-set #
Toggle UI prompts displayed during operations.
Signature:
Public Property Let DisplayPrompts(ByVal state As Boolean)
When False, suppresses folder-picker dialogs and other interactive prompts. Primarily used by automated tests.
Parameters:
state: Boolean. True to enable prompts.
Application state coordination
application-scope #
Guard Excel with the reusable ApplicationState scope.
Signature:
Private Function ApplicationScope() As IApplicationState
enter-busy-state #
Apply the busy state when heavy work starts.
Signature:
Private Sub EnterBusyState()
leave-busy-state #
Restore Excel configuration when work completes.
Signature:
Private Sub LeaveBusyState(Optional ByVal silent As Boolean = False)
Workbook-driven import
import-dictionary #
Import dictionary worksheet using LLdictionary.
Signature:
Private Sub ImportDictionaryUsingClass(ByVal pass As IPasswords, _
ByVal hostWorkbook As Workbook, _
ByVal importWorkbook As Workbook)
import-choices #
Import choices worksheet using LLChoices.
Signature:
Private Sub ImportChoicesUsingClass(ByVal pass As IPasswords, ByVal hostworkbook As Workbook, ByVal importworkbook As Workbook)
import-exports #
Import export specifications via LLExport.
Signature:
Private Sub ImportExportUsingClass(ByVal pass As IPasswords, _
ByVal hostWorkbook As Workbook, _
ByVal importWorkbook As Workbook)
import-analysis #
Import analysis worksheet content via Analysis class.
Signature:
Private Sub ImportAnalysisUsingClass(ByVal pass As IPasswords, _
ByVal hostWorkbook As Workbook, _
ByVal importWorkbook As Workbook)
import-translations #
Import translations worksheet using CustomTable and SetupTranslationsTable.
Signature:
Private Sub ImportTranslationsUsingClass(ByVal pass As IPasswords, _
ByVal hostWorkbook As Workbook, _
ByVal importWorkbook As Workbook)
resolve-translations-list #
Resolve the translations ListObject from a worksheet.
Signature:
Private Function ResolveTranslationsList(ByVal sheetRef As Worksheet, _
Optional ByVal preferred As ListObject = Nothing) As ListObject
Preparation helpers
prepare-import #
Ensure the exports and dictionary sheets are aligned prior to import.
Signature:
Private Sub PrepareImport(ByVal pass As IPasswords, _
Optional ByVal sheetsList As BetterArray, _
Optional ByVal forceSync As Boolean = True, _
Optional ByVal impStartRow As Long = EXPORT_HOST_START_ROW, _
Optional ByVal impStartColumn As Long = EXPORT_HOST_START_COLUMN, _
Optional ByVal renameChoices As Boolean = False)
post-import #
Restore choices column names after import completes.
Signature:
Private Sub PostImport(ByVal pass As IPasswords, _
Optional ByVal sheetsList As BetterArray)
Validation helpers
resolve-import-sheets #
Resolve the requested sheets set, defaulting to core setup worksheets.
Signature:
Private Function ResolveImportSheets(ByVal sheetsList As BetterArray) As BetterArray
default-import-sheets #
Default sheet list covering the core setup worksheets.
Signature:
Private Function DefaultImportSheets() As BetterArray
should-import-sheet #
Determine whether a sheet should participate in the import.
Signature:
Private Function ShouldImportSheet(ByVal sheetsList As BetterArray, ByVal sheetName As String) As Boolean
ensure-import-selection #
Ensure at least one import option is selected.
Signature:
Private Sub EnsureImportSelection(ByVal importDictionary As Boolean, _
ByVal importChoices As Boolean, _
ByVal importExports As Boolean, _
ByVal importAnalysis As Boolean, _
ByVal importTranslations As Boolean, _
ByVal cleanSetup As Boolean)
ensure-import-path-configured #
Ensure the import path has been configured.
Signature:
Private Sub EnsureImportPathConfigured(ByVal value As String)
validate-passwords #
Validate availability of requested passwords object.
Signature:
Private Sub ValidatePasswords(ByVal pass As IPasswords)
ensure-sheets-list #
Ensure the sheets list is initialised.
Signature:
Private Function EnsureSheetsList(ByVal sheetsList As BetterArray) As BetterArray
validate-import-path #
Confirm the import path string is valid.
Signature:
Private Sub ValidateImportPath(ByVal pathValue As String)
validate-progress-display #
Ensure the progress display object exposes a Caption or Value property.
Signature:
Private Sub ValidateProgressDisplay(ByVal progressDisplay As Object)
test-property #
Test whether an object supports a named property.
Signature:
Private Function TestProperty(ByVal Obj As Object, ByRef hasProp As Boolean, Optional ByVal propName As String = "Caption") As Boolean
ensure-import-file-exists #
Ensure the import workbook file exists before opening.
Signature:
Private Sub EnsureImportFileExists(ByVal filePath As String)
Workbook helpers
ensure-import-workbook #
Obtain the imported workbook, opening it when needed.
Signature:
Private Function EnsureImportWorkbook() As Workbook
ensure-export-workbook #
Obtain or create the export workbook, prompting for a folder when needed.
Signature:
Private Function EnsureExportWorkbook() As Workbook
ensure-saved-export #
Save the export workbook to the configured path.
Signature:
Private Sub EnsureSavedExport()
resolve-dictionary-format #
Return format header names when the sheet is the dictionary.
Signature:
Private Function ResolveDictionaryFormat(ByVal sheetName As String) As BetterArray
build-export-file-path #
Build the timestamped export file path from the configured folder.
Signature:
Private Function BuildExportFilePath() As String
close-import-workbook #
Close and release the imported workbook.
Signature:
Private Sub CloseImportWorkbook()
close-export-workbook #
Close and release the export workbook.
Signature:
Private Sub CloseExportWorkbook()
close-workbook #
Close workbook safely without raising errors.
Signature:
Private Sub CloseWorkbook(ByVal workbookRef As Workbook)
worksheet-exists #
Detect whether a worksheet exists within a workbook.
Signature:
Private Function WorksheetExists(ByVal workbookRef As Workbook, ByVal sheetName As String) As Boolean
resolve-registry-sheet #
Resolve the registry worksheet if present.
Signature:
Private Function ResolveRegistrySheet(ByVal workbookRef As Workbook) As Worksheet
list-object-exists #
Detect whether a ListObject exists within a worksheet.
Signature:
Private Function ListObjectExists(ByVal sheetRef As Worksheet, ByVal listName As String) As Boolean
Worksheet helpers
clean-worksheet-tables #
Clean all ListObjects within a worksheet.
Signature:
Private Sub CleanWorksheetTables(ByVal targetSheet As Worksheet)
clear-worksheet-comments #
Remove both classic and threaded comments from a worksheet.
Signature:
Private Sub ClearWorksheetComments(ByVal targetSheet As Worksheet)
protect-worksheet #
Protect worksheet with default rules.
Signature:
Private Sub ProtectWorksheet(ByVal pass As IPasswords, ByVal sheetName As String)
Messaging helpers
write-info #
Display informational text through the progress object.
Signature:
Private Sub WriteInfo(ByVal message As String)
write-progress #
Update a textual progress bar representation.
Signature:
Private Sub WriteProgress(ByVal percentage As Integer)
build-open-failure-message #
Combine failure details when opening a workbook fails.
Signature:
Private Function BuildOpenFailureMessage(ByVal sourcePath As String, ByVal failureDetails As String) As String
Error handling
report-and-throw #
Report message then raise a project error.
Signature:
Private Sub ReportAndThrow(ByVal errNumber As ProjectError, ByVal message As String)
throw-error #
Raise a ProjectError-based exception.
Signature:
Private Sub ThrowError(ByVal errNumber As ProjectError, ByVal message As String)
terminate #
Cleanup resources on destruction.
Signature:
Private Sub Class_Terminate()
Interface implementation
ISetupImportService_Check #
Signature:
Private Sub ISetupImportService_Check(ByVal importDictionary As Boolean, _
ByVal importChoices As Boolean, _
ByVal importExports As Boolean, _
ByVal importAnalysis As Boolean, _
ByVal importTranslations As Boolean, _
Optional ByVal cleanSetup As Boolean = False)