Is there a way to read lines of a module

G

Guest

I would like for a VBA macro to be able to read the lines of one of its
modules as data so that the macro can do something with. Is that possible?

What follows is only a specific example. Suppose I have a module that
contains:
Public Const rName as String="MySheet!A"
Public Const rAddr as String="MySheet!B"
Public Const rDog as String="MySheet!C"
I would like the macro to beable to read the above 3 lines (along with
whatever else is in the module) and set row 1 (the column headers) of
MySheet to: Name, Addr, and Dog

Thanks for your help!
 
C

Chip Pearson

You can use code like

Dim S As String
With ActiveWorkbook.VBProject.VBComponents("Module2").CodeModule
S = .Lines(1, .CountOfLines) ' note leading periods
End With
Debug.Print S

This will put the contents of the entire Module2 into the variable S.

See also www.cpearson.com/Excel/VBE.htm .


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting
www.cpearson.com
(email on the web site)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top