ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Is there a way to read lines of a module (https://www.excelbanter.com/excel-programming/396822-there-way-read-lines-module.html)

[email protected]

Is there a way to read lines of a module
 
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!


JMB

Is there a way to read lines of a module
 
there is some information here that should help

http://cpearson.com/excel/vbe.htm


" wrote:

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!



Chip Pearson

Is there a way to read lines of a module
 
You can use code like

Dim S As String
With ActiveWorkbook.VBProject.VBComponents("Module2").C odeModule
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)

wrote in message
...
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!


[email protected]

Is there a way to read lines of a module
 
Thanks! Works great!


All times are GMT +1. The time now is 05:52 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com