Open document with macros - or not at all

J

Jan Kronsell

Is there anyway I can force the use of macros in a document. I have document
with som code using the Document_Open event that forces the users to do a
few things before starting to work with the document. But if the users has
there security level set to medium, and replises "No" to the "Open with
macros" question, then dont have to go through my set of userforms.

Is there anyway I can set a document to close immediately, is the users
replies No to open with macros or not to open at all?

Jan
 
C

Charles Kenyon

You can have in place AutoOpen/AutoClose procedures that essentially hide
the contents of the document unless macros are active. That is, the
document, if opened without the AutoOpen macro has no contents and when
closed, the contents are transferred to one or more document variables for
retrieval at a later time. Possibly with a message saying that macro
activation is required to read the document.

This is very far from secure, even with password protection for the vba
project. I would guess that over half of the regular contributors to this
newsgroup could get the contents in less than fifteen minutes.

Formatting would also be a mess. This could be aleviated, with even less
security, by usin AutoText to hold your contents.

You can also protect a document for forms so as to allow no editing unless
macros are active. This is even more insecure than the previous method.

So, if your question is whether you can make a document that requires macros
(or vba skills) to read the content, the answer is "yes." If your question
is whether you can force this on a knowledgable user, the answer is "no."
Macro security, lame though it may be, is pretty central to Microsoft's
security efforts.
 
J

Jan Kr

Maybe its just me, but where do I put the autoopen/autoclose macros for them
in order to work, even if the user decides to disable macros?

Jan

Charles Kenyon said:
You can have in place AutoOpen/AutoClose procedures that essentially hide
the contents of the document unless macros are active. That is, the
document, if opened without the AutoOpen macro has no contents and when
closed, the contents are transferred to one or more document variables for
retrieval at a later time. Possibly with a message saying that macro
activation is required to read the document.
Maybe its just me, but where do i put the autoopen/autoclose macros for them
in order to work, even if the user deciedsto disable macros?
 
J

Jezebel

In the document itself, in the template on which the document is based, or
in an add-in.
 
C

Charles Kenyon

If the user decides to disable macros, your macros do not work. What I was
pointing out is a kludge. It is designed to deny the user the benefit of
opening the document if they do not enable macros. That is, the content of
the document is available only to someone who enables the macros to put that
content into the document. You cannot force someone to enable macros.

In a corporate environment, you can sign your macros. You can put them in
your templates and have the templates marked as trusted sources.
 
J

Jonathan West

Jan Kr said:
Maybe its just me, but where do I put the autoopen/autoclose macros for them
in order to work, even if the user decides to disable macros?

You can't. If you could, the security features that allow macros to be
disabled would be worthless.
 
J

Jan Kronsell

Thank you all. You confirnmed what I suspected. Sp I guess I just have to
think of something else.

Jan
 
J

Jonathan West

Jan Kronsell said:
Thank you all. You confirnmed what I suspected. Sp I guess I just have to
think of something else.


Describe what you are trying to achieve. Forget about the means you were
thinking of using, just describe the overall objective. We might be able to
suggest an alternative approach.
 
J

Jan Kronsell

I have a document (a form). It has a few locked sections, and one unlocked
section for free text entry. The locked sections contain form fields for the
user to enter data in. This Works perfectly ok. But the user also has to
enter som variable information into the header and footer of the document as
well, and as far as I have been able to figure out, you can't have form
fields in the header or footer (Word XP btw).

In stead I have created a number of bookmarks in the header and footer. I
have then created a userform, in which the user enters the information for
the bookmarks. The bookmarks are then replaced with the values from the
userform using code. When the document is opened, the userform is shown, and
you have to fill out the fields in order to continue. If you press Cancel,
the document is closed. When the user has completed the userform, he
continues to the rest of the form document. If the fields (bookmarks) in
header and footer is not filled out, he mustnot be able to continue with the
form.

But if he disables macros, the userform is not shown at all, and the code,
that makes sure the document is closed if the form is not completed will not
run of course. in that case the document is shown, and he will be able to
fill out the form fields, without filling out the variable information in
the header and footer.

So to put it simple: My problem is enforcing the user to fill out variable
information in the header and footer of a locked document (and of course he
must not be able to change other information in the header and footer
either).

Jan
 
J

Jonathan West

Jan Kronsell said:
I have a document (a form). It has a few locked sections, and one unlocked
section for free text entry. The locked sections contain form fields for the
user to enter data in. This Works perfectly ok. But the user also has to
enter som variable information into the header and footer of the document as
well, and as far as I have been able to figure out, you can't have form
fields in the header or footer (Word XP btw).

In stead I have created a number of bookmarks in the header and footer. I
have then created a userform, in which the user enters the information for
the bookmarks. The bookmarks are then replaced with the values from the
userform using code. When the document is opened, the userform is shown, and
you have to fill out the fields in order to continue. If you press Cancel,
the document is closed. When the user has completed the userform, he
continues to the rest of the form document. If the fields (bookmarks) in
header and footer is not filled out, he mustnot be able to continue with the
form.

But if he disables macros, the userform is not shown at all, and the code,
that makes sure the document is closed if the form is not completed will not
run of course. in that case the document is shown, and he will be able to
fill out the form fields, without filling out the variable information in
the header and footer.

So to put it simple: My problem is enforcing the user to fill out variable
information in the header and footer of a locked document (and of course he
must not be able to change other information in the header and footer
either).

Try putting REF fields into the header & footer which reference the
bookmarks associated with the matching formfields. These should be able to
update without the need for VBA to force an update.
 
J

Jan Kronsell

Try putting REF fields into the header & footer which reference the
bookmarks associated with the matching formfields. These should be able to
update without the need for VBA to force an update.
I may have expressed myself unclear. The variable info in the header and
footer has nothing to do with any of the form fields in the document it
self. So there is no bookmarks I can reference.

Jan
 
C

Chad DeMeyer

The way I handle this in the forms I design is to take the "header" fields
out of the Header in the first section, so the user can fill in this
information in form fields on the first page. I bookmark this and then use
a REF field in the header of the second section, keeping 'Same as previous'
for the headers of any additional sections. This is not too onerous because
I use "New Portrait Form.dot" and "New Landscape Form.dot", which are
templates I have already set up this way.

Regards,
Chad DeMeyer
 

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