Determine when Module was added/updated

U

utnj

I created a number of standard modules that contain code for
formatting and printing various documents.

The problem is, these documents are accessed through a seperate VB
Application that adds its own code modules (disables Save, SaveAs,
etc) and appears to delete any code from the first module that I
created.

The solution I currently have is to put a bunch of comments in a
module, and add that to the project first. When the application runs,
it then deletes the code which I do not need.

But I am curious how the VB application determines which module to
delete the code from. Is this only exposed to VB? or can I read these
properties using VBA as well? I tried looking through the Object
Browser but didnt see anything other than how to set the name.
 
S

Shauna Kelly

Hi

Yes, you can get programmatic access to the VBA. Look up VBProject in the
VBA help for all the details.

However, your code can only access the VBA code if, at Tools > Options >
Security > Macro Security and on the Trusted Publishers tab, you have turned
on "Trust access to Visual Basic Project".

Hope this helps.

Shauna Kelly. Microsoft MVP.
http://www.shaunakelly.com/word
 
U

utnj

I looked up VBProject in the VBA Help but it wasn't much help (go
figure)

I am having a hard time finding information on how to find details
about the individual modules (VBComponents???) but I came up with the
following code to loop through the parts of the project and show the
module name. I will play around with a bit more and look at the
debugger to see what else I can see

Dim iCnt, strModName
For iCnt = 1 To ActiveDocument.VBProject.VBComponents.count
strModName =
ActiveDocument.VBProject.VBComponents.Item(iCnt).Name
msgbox strModName
Next

Thanks for the help
 
P

Perry

There are more tools available in the VBA extensibility library.
"Microsoft Visual Basic for Application Extensibility 5.3 library"
Set a reference to this library.
Note:
the VB Project security settings (trust Access to yr VB Project)
If the code needs to run on clients in a network, you will also have to
deal with the enterprise security settings/policies ...

Anyhow once the VBA ext library reference is set, code like
in below snippet is available (and there's a lot more ...)

With ThisDocument.VBProject.VBComponents
For x = 1 To .Count
With .Item(x).CodeModule
Debug.Print .CountOfLines
Debug.Print .Parent.Name
.DeleteLines 1, 5 '<< delete lines
End With
Next
End With

--
Krgrds,
Perry

System:
Vista/Office Ultimate
VS2005/VSTO2005 SE
 

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