Macros that prevent modification of a doc x number of day after sa

R

rcoppi

I have an application that invokes MS WORD to generate documents necessary
for tasks completed within the application. I currently have macros that
link the two applications together but I need to create a macro or something
that would prevent a single document or a group of mail-merge documents
generated from being modified X number of days after the document(s) were
originally saved. Any ideas? We just switched from DDE to OLE if that helps.
 
J

Jay Freedman

rcoppi said:
I have an application that invokes MS WORD to generate documents
necessary
for tasks completed within the application. I currently have macros
that link the two applications together but I need to create a macro
or something that would prevent a single document or a group of
mail-merge documents generated from being modified X number of days
after the document(s) were originally saved. Any ideas? We just
switched from DDE to OLE if that helps.

There isn't a lot of detail here. Who or what would be attempting to change
the documents, either before or after the cutoff date? What version of Word
is being used? Where are the current batch of macros -- somewhere in Word,
or in this other application (and what is that?)?

Word in general has a lot of trouble with this sort of task. Yes, you can
write an AutoOpen macro that compares the current date to the document's
creation date and, when necessary, applies some form of protection. If
you're working with Word 2003 or later, there is a "No changes (Read only)"
protection that can be applied with a password; in Word 2002 and earlier,
the best you can do is forms protection, whose password is easily bypassed.

There are two problems with this approach: (a) Macros stored in documents
(as opposed to those in templates in trusted locations) are considered
likely to be viruses, so the user may be required to enable them, or they
may just be disabled silently, depending on security settings. (b) Even if
macros would normally be enabled, any AutoOpen macro can be prevented from
running by holding down the Shift key. So if you're concerned with a
deliberate "attack" on a document that shouldn't be modified, the macro
won't be an adequate defense.

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.
 
R

rcoppi

Hi Jay,

Here is a little more detail for you. We are currently invoking Word 2003.
Our functionality incorporates several macros:
1) one that begins the document generation process. Main (Execution begins
here), Reads the name of the data file that was passed from POSSE, opens it
and reads the merge template name, the Document Request ID, and the Worker
name from the first record. The extract file is then closed and merged with
the requested merge template.adds the necessary buttons to the menu bar;
2) one thate deletes the buttons from the menu bar once the worker selects
one of the buttons,
3) one that adds the 3 new buttons used by the document generation process,
4) one that handles the "Return to application without saving changes"
functionality (one of the 3 buttons),
5) one that handles the "Return to application and save changes"
functionality (second of the 3 buttons), CSEEditDocOK. This macro is invoked
when the Return to POSSE - SAVE changes button is selected. If changes to
the document are detected, it will remove headers inserted in an earlier
macro, save the file in DOS text format, record successful completion in the
status work file, and then call a macro to return to POSSE;
6) one handles the find the next insert text field (third of 3 buttons), and
7) one that allows the worker to retrieve a previously generated and save
document I believe this is where I would need to put the new code to prevent
the workers from making changes to any document or group of documents
retrieved using this functionality 8 days after the document(s) was/were
originally modified. This macro Retrieves the document request ID that was
passed from POSSE, attempts to open all related documents. If no saved
documents could be found under that document request ID, an error message is
displayed.

We have added code to each of the macros we are currently using that
prevents the workers from canceling execution of the macros.

The sequence of events would be similar to the following:
1. The end-user (worker) would be in our application.
2. The worker would click the "Generate" button from the appropriate screen
in our application, to invoke Word 2003, open the document template, and
merge the appropriate data from our application into the new document.
Sometimes there are multiple documents are generated from different templates
at the same time. This is were we are having the problem. Our new code
allows us to protect the first document but workers can still make changes to
the other documents in that grouping.
3. When the worker is satisfied with the contents of the document, they
would click another button entitled "Return to POSSE Save" which closes Word
and saves the modified document in a specified directory.
4. If the worker "Retrieves" the document(s) using the retrieve macro
functionality any time from the time it was modified and saved in step 3
until the end of the 7th day is allowed, but on the 8th day, no modifications
should be allowed to the retrieved document(s).

I hope this helps! Thank you!
 
J

Jay Freedman

Since you're using Word 2003, you have a protection method available to you. In
the "Retrieve" macro, include code like this (setting a password is optional,
but if you do set it, don't forget what it is!):

Dim DocAgeInDays As Variant
With ActiveDocument
DocAgeInDays = DateDiff("d", .BuiltInDocumentProperties _
(wdPropertyTimeCreated), Now)
If DocAgeInDays > 7 Then
If .ProtectionType <> wdAllowOnlyReading Then
.Protect Type:=wdAllowOnlyReading, _
NoReset:=True, Password:="secret"
.Save
End If
End If
End With

It sounds like you also should set up some code that, when more than one
document is generated at one time, saves the names of the extra documents
somewhere in the main document -- perhaps as document variables, which aren't
visible to users but can be written and read by macros. That way, when the main
document is retrieved, the extra documents can also be retrieved and protected.
 

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