VBA Code Access

D

Dave

Is it possible to programmatically access a code module in Excel so the
text can be read?

I've read code that suggests that module code can be added, but not read.

Haven't attempted adding since it serves me no purpose.

Thanks in advance
 
R

RB Smissaert

How about export the module and then read it:

Sub Testing()
ThisWorkbook.VBProject.VBComponents("Test").Export "C:\Test.bas"
End Sub

The .bas file can then be read with for example Notepad or you can open it
in Excel (sheet) itself.
You will need to set a reference to the Microsoft Visual Basic for
Applications Extensibility library.


RBS
 
C

Chip Pearson

You will need to set a reference to the Microsoft Visual Basic
for Applications Extensibility library.

No, no reference is required for that code to run.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
 
D

Dave

TC said:
Why do you want to? What are you trying to achieve?

TC
It would be handy to be able to scan for version info as well as aid in
documentation. I could parse an exported BAS file but that might not be
complete. Also, comparing modules from book to book.

Thanks
 
D

Dave

Chip said:
What do you mean that a code module be "read"?
I want to be able to parse the code programmatically from within a
procedure. This will provide for book to book comparison and version
checking, etc. etc.
 
D

Dave

RB said:
How about export the module and then read it:

Sub Testing()
ThisWorkbook.VBProject.VBComponents("Test").Export "C:\Test.bas"
End Sub

The .bas file can then be read with for example Notepad or you can open
it in Excel (sheet) itself.
You will need to set a reference to the Microsoft Visual Basic for
Applications Extensibility library.


RBS
This might be a workaround. Once exported, I could open the file and
parse what I need.

I would like to be able to provide for comparing modules from book to
book, version controls, and simple doc prep.

Thanks. I'll play with this for a bit.
 
T

TC

Parsing the exported file would work fine, IMHO. There's nothing in the
module, that you will not see in that file.

As an aside: MS Access VBA has methods to read the source lines from a
module. So, the ability to do this, does vary, depending on which
product's VBA you have in mind.

Cheers,
TC
 
D

Dave

TC said:
Parsing the exported file would work fine, IMHO. There's nothing in the
module, that you will not see in that file.

As an aside: MS Access VBA has methods to read the source lines from a
module. So, the ability to do this, does vary, depending on which
product's VBA you have in mind.

Cheers,
TC
I would imagine that the VBA in Excel would work in Access. Some
experimenting is due. I will most likely use the most common. Thanks
again.

Dave
 
T

TC

I know for a fact that there are mehods you can use in Word, to add
code to a module, which definitely do not work in Access. So I imagine
there are similar methods in Excel that will not work in Access.

HTH,
TC
 

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