Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How to delete a text file from the macro?

Posted on 2011-03-18
2
Medium Priority
?
271 Views
Last Modified: 2012-06-22
Hi,

do not know how a simple macro that checks at startup if the computer is a text file on path: "%temp%\test.log" and if so, delete it?
I found this, but I do not know exactly how to use it:

http://www.exceltip.com/st/Basic_file_and_folder_examples_using_VBA_in_Microsoft_Excel/443.html

Thanks for your help
0
Comment
Question by:Thomas_Meyer
2 Comments
 
LVL 12

Accepted Solution

by:
Amick earned 2000 total points
ID: 35165602
In the Developer->Visual Basic tab select This Workbook and copy the following code:
Private Sub Workbook_Open()
sTemp = Environ("TEMP")
Kill sTemp + "\test.log"
End Sub

Open in new window


Save the workbook in a trusted directory so that the macro will run upon loading or be sure to enable macros for the workbook when it is opened.
0
 

Author Closing Comment

by:Thomas_Meyer
ID: 35165842
Thanks, perfect.
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this post, I will showcase the steps for how to create groups in Office 365. Office 365 groups allow for ease of flexibility and collaboration between staff members.
In a use case, a user needs to close an opened report by simply pressing the Escape (Esc) key. This can be done by adding macro code in Report_KeyPress or Report_KeyDown event.
The viewer will learn how to simulate a series of coin tosses with the rand() function and learn how to make these “tosses” depend on a predetermined probability. Flipping Coins in Excel: Enter =RAND() into cell A2: Recalculate the random variable…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…

926 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question