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
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 #
path
Retrieve configured import path.
Signature:
Public Property Get Path() As String
Returns: String. The configured import path.
ProgressObject #
progress-object
Retrieve the progress display object.
Signature:
Public Property Get ProgressObject() As Object
Returns: Object. The progress display object.
DisplayPrompts #
display-prompts
Retrieve the display prompts toggle.
Signature:
Public Property Get DisplayPrompts() As Boolean
Returns: Boolean. True when prompts are enabled.
SetExportFolder #
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.
LastExportFile #
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 #
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
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 #
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
ImportFromWorkbook #
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 #
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
Class_Initialize #
initialize
Set default state on construction.
Signature:
Private Sub Class_Initialize()
Public configuration
Path #
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.
ProgressObject #
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 #
self
Current object instance cast to the interface.
Signature:
Public Property Get Self() As ISetupImportService
Returns: ISetupImportService. The current instance.
DisplayPrompts #
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
ApplicationScope #
application-scope
Guard Excel with the reusable ApplicationState scope.
Signature:
Private Function ApplicationScope() As IApplicationState
EnterBusyState #
enter-busy-state
Apply the busy state when heavy work starts.
Signature:
Private Sub EnterBusyState()
LeaveBusyState #
leave-busy-state
Restore Excel configuration when work completes.
Signature:
Private Sub LeaveBusyState(Optional ByVal silent As Boolean = False)
Workbook-driven import
ImportDictionaryUsingClass #
import-dictionary
Import dictionary worksheet using LLdictionary.
Signature:
Private Sub ImportDictionaryUsingClass(ByVal pass As IPasswords, _
ByVal hostWorkbook As Workbook, _
ByVal importWorkbook As Workbook)
ImportChoicesUsingClass #
import-choices
Import choices worksheet using LLChoices.
Signature:
Private Sub ImportChoicesUsingClass(ByVal pass As IPasswords, ByVal hostworkbook As Workbook, ByVal importworkbook As Workbook)
ImportExportUsingClass #
import-exports
Import export specifications via LLExport.
Signature:
Private Sub ImportExportUsingClass(ByVal pass As IPasswords, _
ByVal hostWorkbook As Workbook, _
ByVal importWorkbook As Workbook)
ImportAnalysisUsingClass #
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)
ImportTranslationsUsingClass #
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)
ResolveTranslationsList #
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
PrepareImport #
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)
PostImport #
post-import
Restore choices column names after import completes.
Signature:
Private Sub PostImport(ByVal pass As IPasswords, _
Optional ByVal sheetsList As BetterArray)
Validation helpers
ResolveImportSheets #
resolve-import-sheets
Resolve the requested sheets set, defaulting to core setup worksheets.
Signature:
Private Function ResolveImportSheets(ByVal sheetsList As BetterArray) As BetterArray
DefaultImportSheets #
default-import-sheets
Default sheet list covering the core setup worksheets.
Signature:
Private Function DefaultImportSheets() As BetterArray
ShouldImportSheet #
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
EnsureImportSelection #
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)
EnsureImportPathConfigured #
ensure-import-path-configured
Ensure the import path has been configured.
Signature:
Private Sub EnsureImportPathConfigured(ByVal value As String)
ValidatePasswords #
validate-passwords
Validate availability of requested passwords object.
Signature:
Private Sub ValidatePasswords(ByVal pass As IPasswords)
EnsureSheetsList #
ensure-sheets-list
Ensure the sheets list is initialised.
Signature:
Private Function EnsureSheetsList(ByVal sheetsList As BetterArray) As BetterArray
ValidateImportPath #
validate-import-path
Confirm the import path string is valid.
Signature:
Private Sub ValidateImportPath(ByVal pathValue As String)
ValidateProgressDisplay #
validate-progress-display
Ensure the progress display object exposes a Caption or Value property.
Signature:
Private Sub ValidateProgressDisplay(ByVal progressDisplay As Object)
TestProperty #
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
EnsureImportFileExists #
ensure-import-file-exists
Ensure the import workbook file exists before opening.
Signature:
Private Sub EnsureImportFileExists(ByVal filePath As String)
Workbook helpers
EnsureImportWorkbook #
ensure-import-workbook
Obtain the imported workbook, opening it when needed.
Signature:
Private Function EnsureImportWorkbook() As Workbook
EnsureExportWorkbook #
ensure-export-workbook
Obtain or create the export workbook, prompting for a folder when needed.
Signature:
Private Function EnsureExportWorkbook() As Workbook
EnsureSavedExport #
ensure-saved-export
Save the export workbook to the configured path.
Signature:
Private Sub EnsureSavedExport()
ResolveDictionaryFormat #
resolve-dictionary-format
Return format header names when the sheet is the dictionary.
Signature:
Private Function ResolveDictionaryFormat(ByVal sheetName As String) As BetterArray
BuildExportFilePath #
build-export-file-path
Build the timestamped export file path from the configured folder.
Signature:
Private Function BuildExportFilePath() As String
CloseImportWorkbook #
close-import-workbook
Close and release the imported workbook.
Signature:
Private Sub CloseImportWorkbook()
CloseExportWorkbook #
close-export-workbook
Close and release the export workbook.
Signature:
Private Sub CloseExportWorkbook()
CloseWorkbook #
close-workbook
Close workbook safely without raising errors.
Signature:
Private Sub CloseWorkbook(ByVal workbookRef As Workbook)
WorksheetExists #
worksheet-exists
Detect whether a worksheet exists within a workbook.
Signature:
Private Function WorksheetExists(ByVal workbookRef As Workbook, ByVal sheetName As String) As Boolean
ResolveRegistrySheet #
resolve-registry-sheet
Resolve the registry worksheet if present.
Signature:
Private Function ResolveRegistrySheet(ByVal workbookRef As Workbook) As Worksheet
ListObjectExists #
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
CleanWorksheetTables #
clean-worksheet-tables
Clean all ListObjects within a worksheet.
Signature:
Private Sub CleanWorksheetTables(ByVal targetSheet As Worksheet)
ClearWorksheetComments #
clear-worksheet-comments
Remove both classic and threaded comments from a worksheet.
Signature:
Private Sub ClearWorksheetComments(ByVal targetSheet As Worksheet)
ProtectWorksheet #
protect-worksheet
Protect worksheet with default rules.
Signature:
Private Sub ProtectWorksheet(ByVal pass As IPasswords, ByVal sheetName As String)
Messaging helpers
WriteInfo #
write-info
Display informational text through the progress object.
Signature:
Private Sub WriteInfo(ByVal message As String)
WriteProgress #
write-progress
Update a textual progress bar representation.
Signature:
Private Sub WriteProgress(ByVal percentage As Integer)
BuildOpenFailureMessage #
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
ReportAndThrow #
report-and-throw
Report message then raise a project error.
Signature:
Private Sub ReportAndThrow(ByVal errNumber As ProjectError, ByVal message As String)
ThrowError #
throw-error
Raise a ProjectError-based exception.
Signature:
Private Sub ThrowError(ByVal errNumber As ProjectError, ByVal message As String)
Class_Terminate #
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)