• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 297
  • Last Modified:

to enable autoclose timers in word file

I would like to enable a a timer  say 1hr when a word file is opened for editing and it should automatically save and close with password protect the file and only the author should know the password.
0
hivos
Asked:
hivos
  • 4
  • 2
1 Solution
 
darbid73Commented:
There are a thousand questions and things that can happen here.

Here is your starting code for the actual timer you need to add your time value as you want.

Sub Document_Open() 
    Application.OnTime When:=Now + TimeValue("00:00:00"), Name:="CloseDoc" 
End Sub 
 
Sub CloseDoc() 
    Dim oSH As Shape 
    'Do you magic here 
    
End Sub 

Open in new window


Lets start with some questions (as I am sure I will not get them all)
What version of word?
What happens if the user blocks vba code when opening the document
Where should the doc be saved?
How should the password be set and when?
What happens if the user closes down the doc before the time is up?
0
 
darbid73Commented:
sorry that code again - cleaned up properly.

Sub Document_Open() 
    Application.OnTime When:=Now + TimeValue("00:00:00"), Name:="CloseDoc" 
End Sub 
 
Sub CloseDoc() 
    
    'Do your magic here 
    
End Sub 

Open in new window

0
 
hivosAuthor Commented:
Thanks, but
I wanted with a password protection feature so that only owner of the file for the current vb macro could open the file again after it is saved and closed
0
Become an Android App Developer

Ready to kick start your career in 2018? Learn how to build an Android app in January’s Course of the Month and open the door to new opportunities.

 
darbid73Commented:
<I wanted with a password protection feature so that only owner of the file for the current vb macro could open the file again after it is saved and closed>

Yes I know that.  but before I get out my crystal ball how about you let us know a little but more about how this should happen.

eg can the user choose a password? etc see my comments above.

If the save as with password is all you want to put into the routine CloaseDoc then here is the MSDN theory and example
0
 
hivosAuthor Commented:
Sorry, I didn't read your comments
This assignment is to create document with necessary code to have built in timer say 1 hr
for the interview candidate to work on the document,
I have enabled timer feature, with auto save and auto close and it is working fine.
and the document is stored/saved in default location (i.,e its original location he/she copies the
document first time)

You are right I didn't think about if he/she closes  the document before 1hr
a) any suggestion on it is welcome
b) I never thought about how to remove macro security restrictions on the file except I have
    stored the file as macro enabled file and requested the candidate to remove the macro security the
    feature or warning. - alternative suggestions are welcome
c) This password feature I though the interview candidate should not know so that he/she does
    not have second access to the file once the file is closed
    -suggestions on it is welcome

Last but not the least; any way we could trace how long the candidate was working on the document file (since we wanted to restrict the document to be accessed for 1hr maximum)

Regards
manju
0
 
darbid73Commented:
a) You could use the event of the document closing and check to see if the timer is closing it or not.  Just use a true false flag.  Set the flag to true when it opens and in the timer event sent it to false before closing.  Then in the close event of the doc check to see if this flage is true or not.  Now you know the reason the document is closing.

b) This is a little bit outside my knowledge, it depends on your version of office and where you have it saved etc.  Is this going to be on a computer you control or on their own computers.

c) and your other question - The problem I am seeing (and I think someone else might offer some other solution) is you need to store information somewhere.  For example if you just put the password in your code then the person could read the password.  I have access to databases, so I would get a password from the database which is going to not show up for the user.  Also when closing I would save the time in the database. You will be able to calculate this when they close the doc.  But where do you want to save it?  

Thinking outside the box - you might be able to "hide it" in the word doc or you could have a text file where you store these things.

There are some word experts here which might give you some more work arounds here.
0

Featured Post

[Webinar] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now