ExportButton

WithEvents wrapper that listens to an MSForms.CommandButton on a linelist export sheet and performs a custom export when clicked. The factory wires the button, an optional filter checkbox, and translation/workbook references. On click, RunExport selects a folder, optionally confirms filter usage, syncs the filtered companions through FilteredData, then delegates to LLExporter.ExportCustom. A sheet the sync skipped aborts the export through the click handler's error path. The factory returns the concrete class because the caller holds a reference to keep the WithEvents binding alive. That caller is the F_Export code-behind, which keeps one instance per button in a module-level collection for as long as the form carries the buttons.

Depends on: LLExporter, FilteredData, ApplicationState, OSFiles

Factory

Create #

create

Create an export button wrapper

Signature:

Public Function Create(ByVal sourceWkb As Workbook, _
                       ByVal trads As TranslationObject, _
                       ByVal expBtn As MSForms.CommandButton, _
                       Optional ByVal expChk As MSForms.CheckBox = Nothing) As ExportButton

Factory method that validates the workbook, translations, and button are not Nothing, then wires the WithEvents binding and optional filter checkbox. Called on the predeclared instance. Returns the concrete class because the caller holds a reference to keep the WithEvents binding alive.

Parameters:

  • sourceWkb: Workbook. The linelist workbook.
  • trads: TranslationObject. Translations for user-facing messages.
  • expBtn: MSForms.CommandButton. The button to listen to.
  • expChk: Optional MSForms.CheckBox. Filter checkbox, or Nothing. Defaults to Nothing.

Returns: ExportButton. A wired instance ready to handle click events.

Throws:

  • ProjectError.ObjectNotInitialized When sourceWkb, trads, or expBtn is Nothing.

Public Accessors

ExportNumber #

export-number

Export number derived from button name

Signature:

Public Property Get ExportNumber() As Long

Reads the button Name property, takes the NAMETAG prefix ("CMDExport") off the front and reads the digits that follow. "CMDExport1" answers 1 and "CMDExport3" answers 3.

The property answers 0 for every name it cannot place: no button bound, a name that does not lead with the tag, a remainder with no digits in it, and a number outside the Long range. The read runs on the click path, so it raises nothing and RunExport refuses the 0.

Returns: Long. The 1-based export number, or 0 when the name carries none.


UseFilter #

use-filter

Whether the filter checkbox is checked

Signature:

Public Property Get UseFilter() As Boolean

Returns the current value of the filter checkbox. Returns False when no checkbox was bound.

The box is read only. Every export button on the form reads the same one, and two exports never run at the same time, so the box holds the user's standing wish and the confirmation is answered per export.

Returns: Boolean. True when the filter checkbox is checked.


Internal members (not exported)

Public Accessors

SourceWorkbook #

source-workbook-set

Assign the source linelist workbook

Signature:

Public Property Set SourceWorkbook(ByVal wb As Workbook)

Parameters:


Translations #

translations-set

Assign the translations object

Signature:

Public Property Set Translations(ByVal trads As TranslationObject)

Parameters:


PushButton #

push-button-set

Wire the WithEvents button binding

Signature:

Public Property Set PushButton(ByVal expBtn As MSForms.CommandButton)

Parameters:


FilterCheckBox #

filter-checkbox-set

Assign the optional filter checkbox

Signature:

Public Property Set FilterCheckBox(ByVal expChk As MSForms.CheckBox)

Parameters:


Seal #

seal

Prevent further changes to setup-only properties

Signature:

Public Sub Seal()

GuardNotSealed #

guard-not-sealed

Raise when a setup-only property is written after sealing

Signature:

Private Sub GuardNotSealed(ByVal propName As String)

Parameters:


Event Handler

Btn_Click #

btn-click

Handle button click event

Signature:

Private Sub Btn_Click()

A click that arrives while this button is already exporting is dropped. Screen updating is off for most of an export, so the form does not repaint and a user who reads that as nothing happening clicks again. The queued click runs when the first export returns, and it would ask for a folder a second time and write a second file.


RunExport #

run-export

Perform a custom export

Signature:

Private Sub RunExport()

Asks the user everything it needs first: the folder through OSFiles, then the filter confirmation. Both questions are answered before the busy state goes on, because a box drawn under suppressed screen updating can end up behind the workbook window on Mac Excel. The busy state then covers the work: the filtered companions are synced and LLExporter.ExportCustom writes the file. The state is restored before the user is told where the file went. On error, displays a translated error message and closes any orphaned output workbook.

Throws:


Private Helpers

TranslatedValue #

translated-value

Get a translated message value

Signature:

Private Function TranslatedValue(ByVal msgCode As String) As String

Parameters:

Returns: String. The translated message text.


ReportSavedFile #

report-saved-file

Tell the user where the file went and what opens it

Signature:

Private Sub ReportSavedFile(ByVal filePath As String, ByVal password As String)

A password-protected export is encrypted with the linelist private key, and that key sits in a very hidden worksheet. A user who is not told it here has no way back to the file, and neither has the colleague they send it to. The key is one value for the whole workbook, so every password-protected export from this linelist shares it and generating a new key changes it for all of them.

Nothing is shown when the export answered no path, which is what a mode that stopped early returns.

Parameters:


SyncFilteredData #

sync-filtered-data

Sync the filtered companions and abort on a skipped sheet

Signature:

Private Sub SyncFilteredData()

Builds a FilteredData over the source workbook and runs the sync. A sheet the sync skipped means the export would read a companion that no longer matches its table, so the failures are joined into one message and raised. The raise lands in RunExport's handler, which shows the message, closes any orphaned output workbook and restores the application state.

Throws:


ThrowError #

throw-error

Raise a ProjectError-based exception

Signature:

Private Sub ThrowError(ByVal errNumber As Long, ByVal message As String)

Parameters:

Throws:


Used in (5 file(s))