ICodeTransfer

Defines the public contract for the CodeTransfer class, exposing methods to transfer VBA code components (classes, modules, forms, workbook code) between workbooks using temporary file export/import cycles.

CodeTransfer

TransferClass #

Transfer a class module from source to target workbook

Signature:

Public Sub TransferClass(ByVal className As String)

Methods for moving VBA components between workbooks. Exports the named class module (.cls) from the source workbook to a temporary file, then imports it into the target workbook.

Parameters:

  • className: String. The VBA component name of the class to transfer.

TransferModule #

Transfer a standard module from source to target workbook

Signature:

Public Sub TransferModule(ByVal moduleName As String)

Exports the named standard module (.bas) from the source workbook to a temporary file, then imports it into the target workbook.

Parameters:

  • moduleName: String. The VBA component name of the module to transfer.

TransferForm #

Transfer a UserForm from source to target workbook

Signature:

Public Sub TransferForm(ByVal formName As String)

Exports the named UserForm (.frm/.frx) from the source workbook to temporary files, then imports it into the target workbook. Both the .frm and .frx files are cleaned up after import.

Parameters:

  • formName: String. The VBA component name of the form to transfer.

TransferWorkbookCode #

Copy code from a source module into the target's ThisWorkbook component

Signature:

Public Sub TransferWorkbookCode(ByVal moduleName As String)

Reads all code lines from the named module in the source workbook and writes them into the target workbook's ThisWorkbook code module, replacing any existing content.

Parameters:

  • moduleName: String. The source module whose code will be copied.

CopyModuleText #

Copy code text from a source module to an existing target module

Signature:

Public Sub CopyModuleText(ByVal moduleName As String)

Reads all code from the named module in the source workbook and writes it into the same-named module in the target workbook, replacing existing content. Used for template workbooks where the target module already exists.

Parameters:

  • moduleName: String. The module name (must exist in both workbooks).

CopyModuleCode #

Copy code between components within the target workbook

Signature:

Public Sub CopyModuleCode(ByVal sourceName As String, ByVal targetName As String)

Within the target workbook, reads code from the source component, writes it into the target component (replacing any existing content), then removes the source component. Useful after importing a module that should be injected into a different component (e.g., a worksheet module or ThisWorkbook).

Parameters:

  • sourceName: String. The component to read code from and then remove.
  • targetName: String. The component to write code into.