Nếu bạn không muốn thêm một mô-đun hoàn chỉnh, bạn có thể chỉ thêm các thủ tục còn thiếu vào một mô-đun hiện có bằng cách sử dụng macro bên dưới. Nó thêm nội dung của một tệp văn bản vào một mô-đun hiện có:

Sub ImportModuleCode(ByVal wb As Workbook, _

ByVal ModuleName As String, ByVal ImportFromFile As String)

' imports code to ModuleName in wb from a textfile named ImportFromFile

Dim VBCM As CodeModule

If Dir(ImportFromFile) = "" Then Exit Sub

On Error Resume Next

Set VBCM = wb.VBProject.VBComponents(ModuleName).CodeModule

If Not VBCM Is Nothing Then

VBCM.AddFromFile ImportFromFile

Set VBCM = Nothing

End If

On Error GoTo 0

End Sub

Ví dụ:

ImportModuleCode ActiveWorkbook, "TestModule", "C:\FolderName\NewCode.txt"