Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 07-12-2014, 01:24 AM
Villalobos Villalobos is offline Kill the file based on date Windows 8 Kill the file based on date Office 2013
Novice
Kill the file based on date
 
Join Date: Jul 2014
Posts: 7
Villalobos is on a distinguished road
Default 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?
Reply With Quote
  #2  
Old 07-13-2014, 04:27 PM
macropod's Avatar
macropod macropod is offline Kill the file based on date Windows 7 32bit Kill the file based on date Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Kill what file? A macro cannot delete any open document - including the one that contains it.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 07-13-2014, 04:46 PM
macropod's Avatar
macropod macropod is offline Kill the file based on date Windows 7 32bit Kill the file based on date Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

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]
Reply With Quote
  #4  
Old 07-14-2014, 03:47 AM
Villalobos Villalobos is offline Kill the file based on date Windows 8 Kill the file based on date Office 2013
Novice
Kill the file based on date
 
Join Date: Jul 2014
Posts: 7
Villalobos is on a distinguished road
Default

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
Reply With Quote
  #5  
Old 07-14-2014, 05:22 AM
macropod's Avatar
macropod macropod is offline Kill the file based on date Windows 7 32bit Kill the file based on date Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

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
As I've already said, though, you can't delete an open document.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #6  
Old 07-14-2014, 05:48 AM
Villalobos Villalobos is offline Kill the file based on date Windows 8 Kill the file based on date Office 2013
Novice
Kill the file based on date
 
Join Date: Jul 2014
Posts: 7
Villalobos is on a distinguished road
Default

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?
Reply With Quote
  #7  
Old 07-14-2014, 09:09 PM
macropod's Avatar
macropod macropod is offline Kill the file based on date Windows 7 32bit Kill the file based on date Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

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]
Reply With Quote
  #8  
Old 07-14-2014, 11:35 PM
Villalobos Villalobos is offline Kill the file based on date Windows 8 Kill the file based on date Office 2013
Novice
Kill the file based on date
 
Join Date: Jul 2014
Posts: 7
Villalobos is on a distinguished road
Default

Thank you the explanation.
I have found an alternative solution... I can delete the file contents with this:
Selection.WholeStory
Selection.Delete
Reply With Quote
  #9  
Old 07-14-2014, 11:43 PM
macropod's Avatar
macropod macropod is offline Kill the file based on date Windows 7 32bit Kill the file based on date Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

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]
Reply With Quote
  #10  
Old 07-06-2017, 09:50 PM
rdross51 rdross51 is offline Kill the file based on date Windows 7 32bit Kill the file based on date Office 2010 32bit
Advanced Beginner
 
Join Date: Feb 2015
Location: Abu Dhabi
Posts: 45
rdross51 is on a distinguished road
Default Complete Code

Quote:
Originally Posted by Villalobos View Post
Thank you the explanation.
I have found an alternative solution... I can delete the file contents with this:
Selection.WholeStory
Selection.Delete
I have a similar need. Can you provide the code you ended up using?
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Kill the file based on date Rules based due date calculation dlowrey Excel Programming 3 05-12-2013 08:30 PM
Kill the file based on date Conditional formatting question based on cell date Cosmo Excel 2 04-08-2013 12:12 PM
Kill the file based on date 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
Kill the file based on date Date auto-populates based on checkbox mcarter9000 Word VBA 5 12-23-2010 12:39 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 03:15 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft