Steve Bell posted the opposite of what you want. He saves the modules in a .xls
workbook to text files. (You want to import the text files, right?)
But that link that Steve gave has code that can import text files into a
workbook's project.
I don't think that this is common at all, but that depends on your definition of
common, I guess.
I took some code from Chip's site and modified it slightly.
Option Explicit
Sub CopyOneModule()
Dim wkbk As Workbook
Dim FName As String
Set wkbk = Workbooks.Add(1)
FName = "c:\module1.bas"
wkbk.VBProject.VBComponents.Import FName
Application.DisplayAlerts = False
wkbk.SaveAs Filename:="C:\myfile.xls", FileFormat:=xlWorkbookNormal
wkbk.Close savechanges:=False
End Sub
This creates a new workbook, imports a text file and saves the workbook.
So the code isn't that difficult.
But one of the reasons I recommend you doing it once instead of everyone do it
once is that there are things that can go wrong.
One security level that was added in xl2002 can stop this kind of code from
running. This is a user by user setting.
And why bother asking some unsophisticated users to do this? I would think that
if you're the developer, you should be doing the heavy lifting. So either
you'll have to do the work or be prepared to answer questions why it doesn't
work.
(Heck, maybe you could have the thing that creates the text file create the .xls
file, too???)
ps. Check Chip's site for lots more things you can do in the VBE.
wrote:
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).
--
Dave Peterson