Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dump all VB source code

Status
Not open for further replies.

CylonLove4Life

Technical User
Feb 15, 2005
53
ES
Is there any way I can dump all of the VB source code - for all the forms and modules - into a text file?
 
One of the ways is to use the (hidden) method .SaveAsText of the application object. It will give you all the other form stuff too, but it works - see thread705-834817 for a reference.

Here's a thread on another way of dumping only the form class module to a text file thread705-716915. Note that when using this, and importing afterwards, you will probably need to reattach all event handlers.

Roy-Vidar
 
Here is another approach, it will dump the code as *.bas files, *.txt files or both.

Add a reference to Microsoft Visual Basic for Extensibility x.x ( I used 5.3 in Excel 2k) then add the following code to a new module:
Code:
Public Function DocumentModule(RootDirectory As String, ExportBas As Boolean, ExportText As Boolean)
'Make sure a root directory was specified
If Len(RootDirectory) = 0 Then
  Exit Function
End If
Dim objProj As VBProject
Dim objComponent As VBComponent
Dim intFile As Integer
Dim strModule As String

Set objProj = Application.VBE.ActiveVBProject
For Each objComponent In objProj.VBComponents
  'Export the files as *.bas files
  If ExportBas Then
    objComponent.Export RootDirectory & "\" & objComponent.Name & ".bas"
  End If
  'Export the modules as *.txt files
  If ExportText Then
    intFile = FreeFile
    Open RootDirectory & "\" & objComponent.Name & ".txt" For Output As #intFile
    strModule = objComponent.CodeModule.Lines(1, objComponent.CodeModule.CountOfLines)
    Print #intFile, strModule
    Close #intFile
  End If
Next objComponent
'Clean up
Set objComponent = Nothing
Set objProj = Nothing
End Function
You feed the [tt]RootDirectory[/tt] in the form [tt]C:\[/tt]

Hope this helps,
CMP


Not sure if this works, I only skimmed the book that came with the software.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top