Recording a Macro to Delete A Day's Work

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello! I am trying to help some of my coworkers learn to use Word. Since we
type medical info, we are not allowed to keep patient information on our
computers (we work at home for a hospital). I would like to make a macro
that we could run that would automatically find and delete all the dictation
that we typed that day so that it will not stay in our computers. I myself
of course know how to delete files manually, but some of the newer users are
petrified of trying anything, so I'd like to make them a macro to do it for
them until they get a little more used to Word. Thank you for any help.
 
I think the question is not clear. Specifically, I initially thought that
you were asking how to delete text in a Word document, but then you say
"delete files".

I am not a Word expert, but I doubt that there is anything in the Word
interface for deleting files. In other words, do you know how use Word to
delete a file without a macro? If so, then the answer to your question is
that you can record a macro to do what you need to do. (Actually, it might
not be as easy as that, since the filenames are likely different, but that
probably does not matter.)

Word is probably not the best tool for that; you can write a script to do
what you need to do. Whether you write a script or a Word macro, the
solution is probably the same in terms of the functions used and such. Look
at the Microsoft TechNet: Script Center at:

http://www.microsoft.com/technet/community/scriptcenter/default.mspx

One very useful thing you can do in particular is download the TechNet
Script Center Sample Scripts as one help file; to do that, see the page I
reference above; I just want to emphasize that it is worthwhile doing
(downloading).
 
Sam, thank you for your reply! I will indeed download the file you suggest.
And just to clarify my question for you or others who might read this: We
type dictation on individual patients, so we may have for instance 20 files
on 20 different patients, none of which we are allowed to keep in our
computers due to confidentiality issues. So what I'm trying to make is a
macro that would automatically go to the files typed today and delete them
all. But you may be right, that Word is not really made to have this
function. I'll try your suggestion, and thank you again!
Teri
 
G'Day Teri,

The Macro language for Office is Visual Basic for Applications
and it still supports the "Kill" statement - an ancient leftover from
the dim and distant past.

IF
all the files can be in the same folder
THEN
the following macro will do the job
END IF
====
Sub DeleteAll()
Dim KillFilePath As String
KillFilePath = "D:\My Documents\Test\*.*"
Kill KillFilePath
MsgBox KillFilePath & vbCrLf & "all files were deleted!"
End Sub
====
Change the folder path of KillFilePath to suit, and you may
also change "*.*" to "*.doc" - but only if you need to.

"*.*" will clean up any temporary files that might get left
over in the event of Word misbehaving.

If there are no files, you will get a non-trappable error
that says "File not found" (press Cancel).

Test it and, better yet, get your colleagues to test it with
and without files.
 
G'Day Sam,

With regard to the Word Interface, be aware that DURING
any file operation (SAVE, OPEN etc) where there is a dialog
open, you may rename or delete any of the visible files.

You are perfectly correct, however, in that this is not a function
of Word and can not be recorded in a Macro.
 
Bearing in mind that the files are not really deleted from your computer,
but merely the filing system no longer points to them when you 'delete' them
then a better file management system would be advisable.

Personally, I would create separate folders - one for each working day -
under the main documents folder, then each day use the appropriate folder to
save your work. You can then delete all files from that folder. If security
is an issue then password protect the documents. Words encryption is very
effective.

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP

My web site www.gmayor.com

<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
On reflection, if you are going to delete daily, then you only need the one
folder for your work from this source.
For the purpose of this exercise, let's make that a sub folder of My
Documents called 'Day Work'

In Notebook (because it is easier) enter the following three lines and save
in the Day Work folder with the filename
DelWork.BAT

@echo off
DEL "D:\My Documents\Day Work\*.DOC"
DEL "D:\My Documents\Day Work\*.WBK"

Change the path in lines 2 and 3 to reflect the full path of Day Work folder
for each user's PC.

Create the following macro in Word, preferably in the template that you use
for this type of work and add it to a toolbar button saved in a custom
toolbar again in that template
(http://www.gmayor.com/installing_macro.htm ). Change the path where
indicated to reflect the location of the batch file.

Sub DelDaysWork()
Dim RetVal, Warning, Text
Text = "WARNING!!" & vbCr & "This will PERMANENTLY delete all the files in
the work folder!"""
Warning = MsgBox(Text, vbOKCancel)
If Warning = 2 Then Exit Sub
If ActiveDocument.Saved = False Then ActiveDocument.Save
Documents.Close
'***********
'Change the path in the following line as appropriate
RetVal = Shell("D:\My Documents\Day Work\delwork.bat", 1)
'***********
End Sub

*Note the warning.* This batch file does not move the deleted files to the
Waste Bin, but removes them permanently.
The batch file will remove any document files and their backup files from
the indicated folder. Other types of file will not be removed, thus I have
chosen to save the batch file in that folder - so don't use your personal
documents folder! The warning message provides an opportunity to reconsider.

As far as confidentiality is concerned, I would have though that if you are
permitted to work on such files in your home environment, then encrypting
them provides far greater security from unauthorised access than simply
deleting them. Stronger measures may be required to ensure that the files
are permanently deleted against recovery and this requires additional
software - eg by using something like Swipe -
http://www.qdsecurity.com/products.html
--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP

My web site www.gmayor.com

<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
VBA also supports the FileSystemObject, which is more powerful and more
portable. New users should learn it instead of the older solutions.
 
This is a little (a lot?) off-topic, but I can suggest other possibilities.
If you choose to pursue one of these, then there are other groups that can
help.

I assume the files do go somewhere before they are deleted, and I assume
they are copied. It might work to simply move them instead of copying them.

Another possibility is to use removable media, and then the documents can
exist only in the removable media. At the end of the day, remove the media
and send to wherever the data is destined for. There are some wonderful
technologies currently available, such as Flash Drives and USB drives. We
can now have a GB of data stored in a device that is about the size of a
postage stamp; the same type of thing used in Cell phones and cameras for
their memory. However for those (Compact Flash cards) we need a
reader/writer, but those are cheap. A USB drive is about the size of a thumb
and plugs directly into a USB port. One place to look for good deals on
things like that is:

http://rasputinj.com
 
Pat, thank you very much!!


Pat Garard said:
G'Day Sam,

With regard to the Word Interface, be aware that DURING
any file operation (SAVE, OPEN etc) where there is a dialog
open, you may rename or delete any of the visible files.

You are perfectly correct, however, in that this is not a function
of Word and can not be recorded in a Macro.
--
Regards,
Pat Garard
Australia
_______________________
 
Sam, thank you very much!

Sam Hobbs said:
This is a little (a lot?) off-topic, but I can suggest other possibilities.
If you choose to pursue one of these, then there are other groups that can
help.

I assume the files do go somewhere before they are deleted, and I assume
they are copied. It might work to simply move them instead of copying them.

Another possibility is to use removable media, and then the documents can
exist only in the removable media. At the end of the day, remove the media
and send to wherever the data is destined for. There are some wonderful
technologies currently available, such as Flash Drives and USB drives. We
can now have a GB of data stored in a device that is about the size of a
postage stamp; the same type of thing used in Cell phones and cameras for
their memory. However for those (Compact Flash cards) we need a
reader/writer, but those are cheap. A USB drive is about the size of a thumb
and plugs directly into a USB port. One place to look for good deals on
things like that is:

http://rasputinj.com
 
Graham, thank you very much!

Graham Mayor said:
On reflection, if you are going to delete daily, then you only need the one
folder for your work from this source.
For the purpose of this exercise, let's make that a sub folder of My
Documents called 'Day Work'

In Notebook (because it is easier) enter the following three lines and save
in the Day Work folder with the filename
DelWork.BAT

@echo off
DEL "D:\My Documents\Day Work\*.DOC"
DEL "D:\My Documents\Day Work\*.WBK"

Change the path in lines 2 and 3 to reflect the full path of Day Work folder
for each user's PC.

Create the following macro in Word, preferably in the template that you use
for this type of work and add it to a toolbar button saved in a custom
toolbar again in that template
(http://www.gmayor.com/installing_macro.htm ). Change the path where
indicated to reflect the location of the batch file.

Sub DelDaysWork()
Dim RetVal, Warning, Text
Text = "WARNING!!" & vbCr & "This will PERMANENTLY delete all the files in
the work folder!"""
Warning = MsgBox(Text, vbOKCancel)
If Warning = 2 Then Exit Sub
If ActiveDocument.Saved = False Then ActiveDocument.Save
Documents.Close
'***********
'Change the path in the following line as appropriate
RetVal = Shell("D:\My Documents\Day Work\delwork.bat", 1)
'***********
End Sub

*Note the warning.* This batch file does not move the deleted files to the
Waste Bin, but removes them permanently.
The batch file will remove any document files and their backup files from
the indicated folder. Other types of file will not be removed, thus I have
chosen to save the batch file in that folder - so don't use your personal
documents folder! The warning message provides an opportunity to reconsider.

As far as confidentiality is concerned, I would have though that if you are
permitted to work on such files in your home environment, then encrypting
them provides far greater security from unauthorised access than simply
deleting them. Stronger measures may be required to ensure that the files
are permanently deleted against recovery and this requires additional
software - eg by using something like Swipe -
http://www.qdsecurity.com/products.html
--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP

My web site www.gmayor.com

<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
For this also, the FileSystemObject can be used directly in the macro to do
the equivalent of the BAT file, eliminating the need for the BAT file.
 
The removable media suggestion is potentially a good one, but unfortunately
Word and such removable media do not sit comfortably together. Recent
security updates have contrived to make it difficult to save to them, not
least because of the potential for document corruption. If this works, there
should not be a problem, provided the documents are small, but with the most
recent version of Windows XP, it could be an issue, and there is always the
potential for document corruption lurking in the background. I would
therefore treat this method with caution.

A removable hard drive may be a better bet, though as with any removable
media there is a danger that it could fall into the wrong hands.

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP

My web site www.gmayor.com

<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
Back
Top