Edit VBA code using code

Z

zSplash

I want to programmatically open a file, then search for and replace text in
the code of that file.

For example, I have a file "Test.dot" that has code setting the default file
path as "C:\Something". I want to modify that code (not my path or my
Normal.dot) -- within the "Test.dot" -- to have the default file path of
"C:\Else". So, when I do it without code, I just search for "C:\Something"
and replace it with "C:\Else" (inside the vba editor of Test.dot), but I
don't know how to do that programmatically.

I hope this makes sense. I really need to know how to modify underlying
code programmatically.

TIA
 
J

Jezebel

Spend some time explorer the nether regions of the Application.VBE object
.... this gives you access to everything you see in the project explorer,
with methods for search and replacing code within the modules.

Rather than replace one string literal with another, may I suggest you
replace it with a constant that is defined at one point in your code? Then
in future if you need to make a change, you just redefine the constant.
 
C

Chad DeMeyer

Also please note, you need to set a reference to Microsoft Visual Basic for
Applications Extensibility x.x (on my Office 2000, x.x = 5.3). This loads
the library for the VBIDE object model.

Regards,
Chad
 
Z

zSplash

Thanks, guys. This is all worse than greek to me.

Jezebel, when I go to the object browser and search for the VBE object, I
get an error telling me "Help Topic Not Available" and indicating that that
my VBA Help cannot be found, or is not fully installed (which it is). I
followed all the instructions to re-install the Help, but I still get the
message. How can I discover more about the VBE object?

Chad, I also have Win2k, and show 6 possible references to VBA: VBA332,
msvvbm60.dll, msvvbm50.dll, VEN2232.OLB, VBAEND32.OLB, and VBAEN32.OLB.
Which is the VBIDE object model, do you think?

st.
 
C

Chad DeMeyer

The actual file name is "VBE6EXT.OLB", but you should find it in the list of
references under the name I specificed "Microsoft Visual Basic for
Applications Extensibility 5.3". Once you set that reference, you should be
able to access the help for its object model.

Regards,
Chad
 
Z

zSplash

Thanks, Chad. Perfect.

st.
Chad DeMeyer said:
The actual file name is "VBE6EXT.OLB", but you should find it in the list of
references under the name I specificed "Microsoft Visual Basic for
Applications Extensibility 5.3". Once you set that reference, you should be
able to access the help for its object model.

Regards,
Chad


or
 

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