View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
STEVE BELL STEVE BELL is offline
external usenet poster
 
Posts: 692
Default VBA text file to .xls

Something from Chip Pearson: http://www.cpearson.com/excel/vbe.htm

Exporting All Modules In A Project
The procedure below will list export all of the modules in a workbook to
text files. It will save the files in the same folder as the workbook. This
can be useful for saving a backup copy of your VBA, or for transferring VBA
code from one project to another.

Sub ExportAllVBA()
Dim VBComp As VBIDE.VBComponent
Dim Sfx As String

For Each VBComp In ActiveWorkbook.VBProject.VBComponents
Select Case VBComp.Type
Case vbext_ct_ClassModule, vbext_ct_Document
Sfx = ".cls"
Case vbext_ct_MSForm
Sfx = ".frm"
Case vbext_ct_StdModule
Sfx = ".bas"
Case Else
Sfx = ""
End Select
If Sfx < "" Then
VBComp.Export _
Filename:=ActiveWorkbook.Path & "\" & VBComp.Name & Sfx
End If
Next VBComp
End Sub



--
steveB

Remove "AYN" from email to respond
wrote in message
oups.com...
Thanks. I am sure you are right about the desirability of providing
an .xls rather than .vba file.

This seems like it might be a common requirement since it effectively
allows one to create an Excel spreadsheet from any language that can
output text, so I was wondering if such a utility already exists?
That is, it would be called from the command line like this:

vba2xls abc.vba abc.xls

where abc.vba is a text file holding vba code that will construct a
spreadsheet and abc.xls is the name to give the xls file that is so
constructed. This utility would automatically run Excel, read in
abc.vba, run the code it just read in and finally save the result
to abc.xls (and preferably not save the abc.vba code which
generated it).