Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default How can delete file by Marco

Hi,

I have problem to delete files, because I only want to delete some
file the name have / include the words of "test" on file name, and I
don't know the path in my local drive (C:). How can I do?

Here is my code for specific path, but how can I change the code for
delete if the file name have / include the words of "test" under my
local drive (C:). Thanks~

On Error Resume Next
Kill "C:\Users\*test*.xl*"
On Error GoTo 0
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default How can delete file by Marco

I also need to delete the file (have / include file name "test") if
the file is open too (active workbook). And don't want to shown the
pop up message on the screen.
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,514
Default How can delete file by Marco

It happens that Hello formulated :
I also need to delete the file (have / include file name "test") if
the file is open too (active workbook). And don't want to shown the
pop up message on the screen.


Uh.., you can't delete an open file so that's not going to fly!

--
Garry

Free usenet access at http://www.eternal-september.org
ClassicVB Users Regroup! comp.lang.basic.visual.misc


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default How can delete file by Marco

is it any way change the file to read only, then can delete files?
if ignore the open file this problem, how can I delete the files
(have / include file name "test"?
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default How can delete file by Marco

So, how can I change the code to delete file name have / include
"test"?


  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,514
Default How can delete file by Marco

on 2/12/2011, Hello supposed :
So, how can I change the code to delete file name have / include
"test"?


I expect you'd need to do a search of all drives/folders to locate all
files that you're looking for. Sounds like you need to spend some time
reading the VB help file. Otherwise, someone who has code for that
needs to step up. (Sorry, but I don't have anything readily available)

--
Garry

Free usenet access at http://www.eternal-september.org
ClassicVB Users Regroup! comp.lang.basic.visual.misc


  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,514
Default How can delete file by Marco

Hello expressed precisely :
is it any way change the file to read only, then can delete files?
if ignore the open file this problem, how can I delete the files
(have / include file name "test"?


No! Windows will not allow you to delete files in use.

--
Garry

Free usenet access at http://www.eternal-september.org
ClassicVB Users Regroup! comp.lang.basic.visual.misc


  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default How can delete file by Marco

Hi Gary,

I don't need the code for delete files in use now.
Could you teach me how can I change the code to delete files when I
need to run this marco on my teammate's (users) computer, not on my
computer, so I cannot search all of drives / folders.

On Error Resume Next
Kill "C:\Users\*test*.xl*"
On Error GoTo 0

Thanks
  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 420
Default How can delete file by Marco


Activeworkbook.ChangeFileAccess Mode:=xlReadOnly
kill activeworkbook.fullname



On 02/11/2011 22:35, Hello wrote:
I also need to delete the file (have / include file name "test") if
the file is open too (active workbook). And don't want to shown the
pop up message on the screen.


--
Dave Peterson
  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default How can delete file by Marco

Hi Dave,

How can I delete file have / include "test" in file name under C drive
and don't know the path? I want to delete all files have / include
"test" .


  #11   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,549
Default How can delete file by Marco


Maybe you should look up the definition of the terms "angry mob" or "fired"...
"New Testament Verses"
"Test Results-Five Year Project"
"My court testimony"
--
Jim Cone
Portland, Oregon USA
http://www.mediafire.com/PrimitiveSoftware
(List Files: specific files/folders with hyperlinks)




"Hello"
wrote in message
...
Hi Gary,
I don't need the code for delete files in use now.
Could you teach me how can I change the code to delete files when I
need to run this marco on my teammate's (users) computer, not on my
computer, so I cannot search all of drives / folders.

On Error Resume Next
Kill "C:\Users\*test*.xl*"
On Error GoTo 0

Thanks



  #12   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 203
Default How can delete file by Marco

"GS" wrote in message
...
on 2/12/2011, Hello supposed :
So, how can I change the code to delete file name have / include
"test"?


I expect you'd need to do a search of all drives/folders to locate all
files that you're looking for. Sounds like you need to spend some time
reading the VB help file. Otherwise, someone who has code for that
needs to step up. (Sorry, but I don't have anything readily available)



Here's a code snippet that finds all the workbook files in the current
folder and calls another procedure for each one. As Garry suggests,
spend some time digging into the VBA help ... perhaps this will help you
along:

' Get list of workbook files in "current" folder
filename = ActiveWorkbook.Path & "\*.xl??"
filename = Dir(filename)

Do
'Debug.Print filename
ExtendIndex ActiveWorkbook.Path & "\" & filename
filename = Dir()
Loop Until filename = ""

Dir is a VBA function, there are related functions that allow you to
change the current directory, etc. .... there is also a file system
object that I have never worked with but might be better suited to your
need.

--
Clif McIrvin

(clare reads his mail with moe, nomail feeds the bit bucket :-)


  #13   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,514
Default How can delete file by Marco

Dave Peterson laid this down on his screen :
Activeworkbook.ChangeFileAccess Mode:=xlReadOnly
kill activeworkbook.fullname



On 02/11/2011 22:35, Hello wrote:
I also need to delete the file (have / include file name "test") if
the file is open too (active workbook). And don't want to shown the
pop up message on the screen.


Thanks, Dave! I didn't think this was possible but I see I was wrong.
This adds a whole new dynamic to file management...

--
Garry

Free usenet access at http://www.eternal-september.org
ClassicVB Users Regroup! comp.lang.basic.visual.misc


  #14   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 420
Default How can delete file by Marco

First, I wouldn't do this kind of thing using excel.

I'd use windows search/find to look for:
*test*.xl*
Then I could look at the results and check to see if each should be deleted.

If I didn't have to verify the results, I could just select all the files on the
right hand side window (by hitting ctrl-a) and hit the delete key.

But if you wanted to search all of drive C: including subfolders, then you could
use application.filesearch in xl2003 and before.

If you're using xl2007 or higher (works in previous versions, too), you can use
code at Ron de Bruin's site to loop through subfolders.

He has a couple of ways he
http://www.rondebruin.nl/fso.htm
and
http://www.rondebruin.nl/copy3.htm

Again, I wouldn't use excel for this -- even though it's possible.

On 02/12/2011 08:51, Hello wrote:
Hi Dave,

How can I delete file have / include "test" in file name under C drive
and don't know the path? I want to delete all files have / include
"test" .


--
Dave Peterson
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Marco to Delete Worksheets CM4@FL Excel Discussion (Misc queries) 2 February 27th 09 07:26 PM
marco to delete empty columns Mike H Excel Programming 0 February 17th 09 09:37 PM
marco to delete empty columns [email protected] Excel Programming 3 February 17th 09 09:09 PM
marco to delete rows Johnfli Excel Discussion (Misc queries) 2 January 11th 07 04:50 PM
A Marco Delete Question [email protected] Excel Programming 1 July 16th 04 08:59 PM


All times are GMT +1. The time now is 06:00 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"