Would Like To Print Source Code for all Forms and Modules in a VB6 project

I have a classic VB6 project which contains forms and modules. I would like to add a Sub procedure to one of the modules which will print to a file the source VB6 code in all the forms and modules in the project. I didn’t know how to do this so I asked ChatGPT 4.0 to write the code for the Sub procedure. ChatGPT generated the code, and I was told to add a reference to “Visual Basic for Applications Extensibility 5.3” to the project. I added the reference and ran the Sub procedure. The program stopped when it reached the line “Set vbProj = VBIDE.VBE.ActiveVBProject”. “VBE” was highlighted and the error message was “Method or data member not found”. Below is the Sub procedure. I would be grateful if someone could suggest a correction to get this to work. Thank you.

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>Public Sub ExportAllCode()
Dim fso As Object
Dim fileStream As Object
Dim vbComp As Object
Dim vbProj As Object
Dim vbComps As Object
Dim vbCompItem As Object
Dim lineNum As Long
Dim codeLine As String
' Create a FileSystemObject to handle the file operations
Set fso = CreateObject("Scripting.FileSystemObject")
' Create or open the output file
Set fileStream = fso.CreateTextFile(App.Path & "AllCode.txt", True)
' Get the VB Project
Set vbProj = VBIDE.VBE.ActiveVBProject
Set vbComps = vbProj.VBComponents
' Loop through all the components (Forms, Modules, Classes) in the project
For Each vbComp In vbComps
' Write the component name to the file
fileStream.WriteLine "Component: " & vbComp.Name
fileStream.WriteLine String(50, "=")
' Write the code lines of the component to the file
For lineNum = 1 To vbComp.CodeModule.CountOfLines
codeLine = vbComp.CodeModule.Lines(lineNum, 1)
fileStream.WriteLine codeLine
Next lineNum
' Add a separator between components
fileStream.WriteLine String(50, "=")
fileStream.WriteLine
Next vbComp
' Close the file
fileStream.Close
' Clean up
Set fileStream = Nothing
Set fso = Nothing
Set vbComp = Nothing
Set vbComps = Nothing
Set vbProj = Nothing
MsgBox "Code export complete. The file 'AllCode.txt' has been created in the application path.", vbInformation
End Sub
</code>
<code>Public Sub ExportAllCode() Dim fso As Object Dim fileStream As Object Dim vbComp As Object Dim vbProj As Object Dim vbComps As Object Dim vbCompItem As Object Dim lineNum As Long Dim codeLine As String ' Create a FileSystemObject to handle the file operations Set fso = CreateObject("Scripting.FileSystemObject") ' Create or open the output file Set fileStream = fso.CreateTextFile(App.Path & "AllCode.txt", True) ' Get the VB Project Set vbProj = VBIDE.VBE.ActiveVBProject Set vbComps = vbProj.VBComponents ' Loop through all the components (Forms, Modules, Classes) in the project For Each vbComp In vbComps ' Write the component name to the file fileStream.WriteLine "Component: " & vbComp.Name fileStream.WriteLine String(50, "=") ' Write the code lines of the component to the file For lineNum = 1 To vbComp.CodeModule.CountOfLines codeLine = vbComp.CodeModule.Lines(lineNum, 1) fileStream.WriteLine codeLine Next lineNum ' Add a separator between components fileStream.WriteLine String(50, "=") fileStream.WriteLine Next vbComp ' Close the file fileStream.Close ' Clean up Set fileStream = Nothing Set fso = Nothing Set vbComp = Nothing Set vbComps = Nothing Set vbProj = Nothing MsgBox "Code export complete. The file 'AllCode.txt' has been created in the application path.", vbInformation End Sub </code>
Public Sub ExportAllCode()
    Dim fso As Object
    Dim fileStream As Object
    Dim vbComp As Object
    Dim vbProj As Object
    Dim vbComps As Object
    Dim vbCompItem As Object
    Dim lineNum As Long
    Dim codeLine As String

    ' Create a FileSystemObject to handle the file operations
    Set fso = CreateObject("Scripting.FileSystemObject")
    
    ' Create or open the output file
    Set fileStream = fso.CreateTextFile(App.Path & "AllCode.txt", True)

    ' Get the VB Project
    Set vbProj = VBIDE.VBE.ActiveVBProject
    Set vbComps = vbProj.VBComponents

    ' Loop through all the components (Forms, Modules, Classes) in the project
    For Each vbComp In vbComps
        ' Write the component name to the file
        fileStream.WriteLine "Component: " & vbComp.Name
        fileStream.WriteLine String(50, "=")
        
        ' Write the code lines of the component to the file
        For lineNum = 1 To vbComp.CodeModule.CountOfLines
            codeLine = vbComp.CodeModule.Lines(lineNum, 1)
            fileStream.WriteLine codeLine
        Next lineNum
        
        ' Add a separator between components
        fileStream.WriteLine String(50, "=")
        fileStream.WriteLine
    Next vbComp

    ' Close the file
    fileStream.Close

    ' Clean up
    Set fileStream = Nothing
    Set fso = Nothing
    Set vbComp = Nothing
    Set vbComps = Nothing
    Set vbProj = Nothing

    MsgBox "Code export complete. The file 'AllCode.txt' has been created in the application path.", vbInformation
End Sub

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật