#1
|
|||
|
|||
Kill the file based on date
Hello,
I would like to ask that is it possible that if the date is "Today" then the macro kill the file? |
#2
|
||||
|
||||
Kill what file? A macro cannot delete any open document - including the one that contains it.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#3
|
||||
|
||||
Cross-posted at: http://www.mrexcel.com/forum/general...e-ms-word.html
For cross-posting etiquette, please read: http://www.excelguru.ca/content.php?184
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#4
|
|||
|
|||
Hello macropod,
My target would be that if the actual date is higher than the pre-definied date (the date is definied in the code), then the code automatically delete the file. The code would be link with the document_open event. Basicly this that code which is working in Excel and I would like to integrate into Word. Option Explicit Private Sub Workbook_open() If date > “2014.07.14” then With ThisWorkbook .Saved = True .ChangeFileAccess xlReadOnly Kill .FullName Application.Quit End With End if End Sub |
#5
|
||||
|
||||
The nearest Word equivalent of that would be:
Code:
Private Sub Document_Open() If Date > DateSerial(2014, 7, 10) Then With ThisDocument .Saved = True Kill .FullName Application.Quit End With End If End Sub
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#6
|
|||
|
|||
Hello Paul,
Thank you for your time. I am very disappointed to can not do it but you are absolutely right, not possible to delete. The code is stop due to Run-Time error '70': Permission denied (at line Kill .FullName). Just for my knowledge. What is reason why this function is not working in Word but working in Excel? |
#7
|
||||
|
||||
Because that's the way Word works. Unlike Excel, Word creates numerous temporary files and these too need to be managed. Simply killing a document and quitting Word would leave these temporary files behind, so Word doesn't allow you to do that.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#8
|
|||
|
|||
Thank you the explanation.
I have found an alternative solution... I can delete the file contents with this: Selection.WholeStory Selection.Delete |
#9
|
||||
|
||||
Somewhat simpler is:
ThisDocument.Content.Delete Note, though, that neither the above nor your code will delete anything from headers or footers.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#10
|
|||
|
|||
Complete Code
I have a similar need. Can you provide the code you ended up using?
|
Thread Tools | |
Display Modes | |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Rules based due date calculation | dlowrey | Excel Programming | 3 | 05-12-2013 08:30 PM |
Conditional formatting question based on cell date | Cosmo | Excel | 2 | 04-08-2013 12:12 PM |
Formula to auto calculate Day of the week based on Date | prasad@dmci.ca | Excel | 1 | 11-29-2011 01:05 PM |
How to count year lapse (rounded off) based on specific date | KIM SOLIS | Excel | 1 | 11-01-2011 10:50 AM |
Date auto-populates based on checkbox | mcarter9000 | Word VBA | 5 | 12-23-2010 12:39 PM |