Prevent to create new document or oped document

B

bzamfir

Hi,

I have an application written in VFP (but this doesn't really mattter,
it could be in VBA too) which nmeeds to allow users to create some DOC
templates for mailmerge.

Specifically, from my app I create a word instance, create a new
document (which will be the mail merge template) and link to the CSV
data source so users can write the letter template and select fields.

To be able to control word, I implement in my app Word's Application2
interface, so I can detect when users close the document (or word) to
save it and close Word too. I use for this event
ApplicationEvents2_DocumentBeforeClose

Also, since I control the template name from external application, I
managed to prevent users to save template with different name, using
event ApplicationEvents2_DocumentBeforeSave, where if SaveAsUI is true,
I set it to false.

I want also to not let users to create or open other documents from
that instance of Word.
Unfortunately I cannot find a way to prevent this. Neither _New nor
_Open events does not have Cancel parameter, and my event handler is
called after default handler.

Also, I saw the events for Document object also does not have Cancel
parameter.

Any suggestion will be appreciated.

Thank you
Bogdan Zamfir
 
J

Jezebel

Ultimately you can't prevent them. But you can go a long way by trapping the
commands themselves: FileNew, FileOpen, etc.
 
B

Bogdan Zamfir

Hi,
Ultimately you can't prevent them. But you can go a long way by trapping the
commands themselves: FileNew, FileOpen, etc.

Thank you for your answer.
Dio you have any idea how to trap FileOpen, FileNew?
I search on google but could not find something.

Regards,
Bogdan
 
J

Jezebel

You write macros with those names.



Bogdan Zamfir said:
Hi,


Thank you for your answer.
Dio you have any idea how to trap FileOpen, FileNew?
I search on google but could not find something.

Regards,
Bogdan
 
B

Bogdan Zamfir

Hi,
You write macros with those names.

Unfortunately I cannot do that, because I cannot create my DOC based on
some template (so to have macros in it), but I automate Word from an
external application.

Is there any way to create macros programatically in a Word DOC from an
by automating Word?

Or those FileOpen, FileNew, are they methods (events, etc) of some
chile object of word.application object. Do you know such object ?

If so, I can "bind" those events / methods to custom methods in my code
so I can trap them this way.

Regards,
Bogdan
 
J

Jezebel

Is there any way to create macros programatically in a Word DOC from an
by automating Word?

This is technically possible (using the methods of the VBE object) but in
practice hard to do and usually blocked by the security settings.
Or those FileOpen, FileNew, are they methods (events, etc) of some
chile object of word.application object. Do you know such object ?

No, it doesn't work that way.


Since you have to install your application on the target computer, why can't
you at the same time install an add-in that contains the necessary code?
 

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