View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Peter T Peter T is offline
external usenet poster
 
Posts: 5,600
Default Exporting Module to Text File

Sub ExportProject()
Dim sPath As String, FName As String, sExt As String
Dim VBComp As Object ' VBIDE.VBComponent
Dim vbp As Object ' VBProject

Set vbp = ActiveWorkbook.VBProject
For Each VBComp In vbp.VBComponents

Select Case VBComp.Type
Case 1: sExt = ".bas"
Case 2, 100: sExt = ".cls"
Case 3: sExt = ".bas"
End Select

FName = sPath & VBComp.Name & sExt
VBComp.Export Filename:=FName
Next

End Sub

You can open an exported code module in a text editor, as indeed you can
almost any file. Note a code module will contain additional text not visible
in the VBE.

Regards,
Peter T

"ExcelMonkey" wrote in message
...
I know from Chip Pearsons site that you can export a code module to a text
file:
http://www.cpearson.com/excel/vbe.aspx

When you do so, you use the Export method of the VBComponent (see below).
My question is: Is this exporting it in its .cls/.bas/.frm format or as
an
actual text file per se?

When I do it, the exported file does not show a file extension and I have
to
chose what program to open it in.

Dim VBComp As VBIDE.VBComponent
VBComp.Export FileName:=FName

Thanks

EM