Embed autoexec routine in a Project(document) derived from a templ

H

Herve cadieu

Hi all,
I would like to know if it is possible that a template.dot can write while
creating a document in the Thisdocument object of the project(Document)
some routines. If yes How to proceed ?
such as :
Sub document_open
"look if a particular DLL is available"
end sub

Or in a custom module added programmatically to the document...
(Is the VBIDE able to do so ?).. as Create object instruction ?
or the like ...
any code snippet is very welcome
Regards
 
T

Tony Jollans

It is possible if rather clumsy but not something one generally needs to do.

The most likely reason for wnting code in a document rather than its
attached template is if the code will be wanted at some time when the
document has become detached from the template - otherwise the code can be
(and should be) run from the template without the hassle (and duplication)
involved in copying it to the document.

Also, if this is for use by people other than yourself they will need, in
2002 and 2003, to have their security set to allow it, which is unlikely for
normal users.

If you really want to do it, one way is along these lines ...

ActiveDocument.VBProject.VBComponents("ThisDocument").CodeModule.AddFromStri
ng _
"Private Sub Document_Open()" & vbCr & _
" ' Your code goes here" & vbCr & _
"End Sub"
 
H

Herve cadieu

Thank you much Tony

I was wondering if it is possible to create an event handler with the same
principle ?
I mean an Object class available in the document resulting from the template.

What I am trying to achieve is :
I have developped a simple yet sexy process to bind a verified handwritten
signature to a digital signature into a document.

I have got an event handler which seeks any changes in the document and
allows to promt the status of the document (tampered or not ) while
associating digital signature to Handwritten signature.

So the mecanism is too complex to be embeded in a document but I would like
to perform a test on avaibility of a certain template on the receiver's
Computer.
If available then proceed
if not propose a download of the required install binary from an url
Search Grapho-Lock on google for more details.

So I would like the document wise enough to check if he has enough .dot
around or download some...

What do you think about it ?
regards
Hervé
 
H

Herve cadieu

Thank you much Tony
I would like to know if it was possible to programmatically digitally sign
the code I add this way in the project document ?
 
T

Tony Jollans

Hi Hervé,

Yes you can write class modules and event code all in the same way. I see no
reason why you shouldn't be able to check for the existence of a dll (or
anything else) and offer to download (and register?) it - I wouldn't be able
to code all that easily myself but, essentially, any VBA code which can be
written can, if you want, be written at run time. I don't know what issues
you might face actually installing a dll on the fly and whether it would be
able to work properly - I guess that would depend on how it worked. It could
also get quite complicated if you wanted to pause code and wait for a
download - but these are all issues to do with running the code, rather than
writing it.
 
T

Tony Jollans

Afraid I have no clue about this. My first thought was that it shouldn't be
possible but on further reflection I don't see any logical reason why it
shouldn't be as the signature would not be acted upon during the run. But I
don't know how the digital signing process works and whether or not it needs
a closed file, etc.
 

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