Do not open without macro

J

Jan Kronsell

I have a document with a maco in it. Is there anyway I can prevent users
from opening the document, without the macro. If security level is medium
they are asked if they want to open with or without macros. What I need is
a sololution that prevents the "without macros" posssiblity.

Jan
 
J

Jezebel

No. A while ago someone posted a document that was encrypted and set up so
that you had to run the AutoOpen macro to decrypt it. The idea was what
you're trying to achieve: if the document was opened without the macro it
was unusable. But it doesn't work. Someone else posted back the unencrypted
document, macro-less, within about 20 minutes.

It's easier just to ask the users to use the macros. Well-behaved users will
do as you ask, and there's nothing you can do about the others anyway.
 
C

Charles Kenyon

You could actually put the contents into your macro, so that the document
without the macro is essentially empty. That is a lot of work. It could be
gotten around easily by someone who knows vba but for most users would be a
block. So, it is not security, just a hinderance.

Without the macro running you could have the contents of the document be an
explanation of how to allow the macro to run.
 
A

Alexis Kachtiane

I had the same problem.

The only solution to "force" the users to enable the
macros is the following:

1) create a protected section (or use an existing
protected section) on the top of the first page of the
document

2) unprotect the document

3) create a text box that entirely recover the first page
of the document (assuming you are in "Page Layout" view")
and check the text box is linked to the protected section

4) fill it with a dark color

5) write a text in the text box (in white, for
example): "Please Close the document and Re-open it,
choosing 'Enable Macros'"

6) reprotect the document: now, each time you open the
document, the text box will prevent the users to use the
first page (they do not know it is only the first page
that is blocked)

7) create the following macro:
Sub SetWarningTextBox(bVisible As Boolean)
UnProtectActiveDoc
ActiveDocument.Shapes(1).Visible = bVisible
ProtectActiveDoc
End Sub
(UnProtectActiveDoc and ProtectActiveDoc are macros that
unprotect and protect the active document document - they
are easy to program)
8) create the AutoOpen macro (or add the following code if
it exists):
Sub AutoOpen
SetWarningTextBox bVisible:=false
End Sub

9) create the FileSave and FileSaveAs macros:
Sub FileSave
SetWarningTextBox bVisible:=true
ActiveDocument.Save
SetWarningTextBox bVisible:=false
ActiveDocument.Saved = true
End Sub

Sub FileSaveAs
With Dialogs(wdDialogFileSaveAs)
If .Display = -1 Then
SetWarningTextBox bVisible:=true
.Execute
SetWarningTextBox bVisible:=false
ActiveDocument.Saved = true
End If
End Sub

10) Now, each time the users open the document enabling
macros, the autoopen macro will hide the text box. But
each time they save the document, the FileSave and
FileSaveAs macros will show the text box just before
saving, and then hide it just after.

Hoping this helps,

Alex
 
J

Jezebel

Easily beaten, Alexis. It's fools' gold to think you can achieve rigorous
security through Word.
 

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