Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How to delete a text file from the macro?

Posted on 2011-03-18
2
Medium Priority
?
268 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Office 365 Training for IT Pros

Learn how to provision tenants, synchronize on-premise Active Directory, implement Single Sign-On, customize Office deployment, and protect your organization with eDiscovery and DLP policies.  Only from Platform Scholar.

Question has a verified solution.

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

This article describes how you can use Custom Document Properties to store settings and other information in your workbook so that they will be available the next time you open the workbook.
New style of hardware planning for Microsoft Exchange server.
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

722 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