Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 08-19-2022, 10:45 PM
soroush.kalantari soroush.kalantari is offline Need help deleting some specific files by an Excel macro Windows 10 Need help deleting some specific files by an Excel macro Office 2016
Competent Performer
Need help deleting some specific files by an Excel macro
 
Join Date: Jun 2021
Posts: 115
soroush.kalantari is on a distinguished road
Default Need help deleting some specific files by an Excel macro

I am trying to delete some specific PowerPoint files which are in a specific folder through following macro. But when running the code, it gives this error”File not found” on the line “Kill MyFiles”. As the attachment shows, the PowerPoint files are in the mentioned folder and by utilizing a MsgBox and clicking on the line which the error occurs, I have ensured that the code identifies the files but, for a unknown reason, it fails to delete them. Can you give me some guides on this issue?

Option Explicit
Sub deletepowepoint()

Dim MyFiles As String

MyFiles = Dir("D:\kalantari\miscellaneous\dailyreport01\*.pp tx")


Do While MyFiles <> "sample.pptx"

Kill MyFiles
MyFiles = Dir
Loop
End Sub
Attached Images
File Type: png Capture01.PNG (103.4 KB, 18 views)

Last edited by soroush.kalantari; 08-20-2022 at 06:54 PM.
Reply With Quote
  #2  
Old 08-20-2022, 06:42 AM
Logit Logit is offline Need help deleting some specific files by an Excel macro Windows 10 Need help deleting some specific files by an Excel macro Office 2007
Expert
 
Join Date: Jan 2017
Posts: 529
Logit is a jewel in the roughLogit is a jewel in the roughLogit is a jewel in the rough
Default

Code:
MyFiles = Dir("D:\kalantari\miscellaneous\dailyreport01\*.pp  tx")

Should the *.pp tx be *.pptx ???
Reply With Quote
  #3  
Old 08-20-2022, 06:57 PM
soroush.kalantari soroush.kalantari is offline Need help deleting some specific files by an Excel macro Windows 10 Need help deleting some specific files by an Excel macro Office 2016
Competent Performer
Need help deleting some specific files by an Excel macro
 
Join Date: Jun 2021
Posts: 115
soroush.kalantari is on a distinguished road
Default

Quote:
Originally Posted by Logit View Post
Code:
MyFiles = Dir("D:\kalantari\miscellaneous\dailyreport01\*.pp  tx")

Should the *.pp tx be *.pptx ???
No, when I paste my code in the site, this space is unexpectedly added and it is not in the original code. (When I click on the edit button to edit the question this space is not exists and I cannot remove it)
Reply With Quote
  #4  
Old 08-20-2022, 07:12 PM
Logit Logit is offline Need help deleting some specific files by an Excel macro Windows 10 Need help deleting some specific files by an Excel macro Office 2007
Expert
 
Join Date: Jan 2017
Posts: 529
Logit is a jewel in the roughLogit is a jewel in the roughLogit is a jewel in the rough
Default

Post your workbook for review.
Reply With Quote
  #5  
Old 08-21-2022, 08:32 PM
soroush.kalantari soroush.kalantari is offline Need help deleting some specific files by an Excel macro Windows 10 Need help deleting some specific files by an Excel macro Office 2016
Competent Performer
Need help deleting some specific files by an Excel macro
 
Join Date: Jun 2021
Posts: 115
soroush.kalantari is on a distinguished road
Default

Quote:
Originally Posted by Logit View Post
Post your workbook for review.
see the attachment.
Attached Files
File Type: xlsm exampleworkbook.xlsm (12.3 KB, 4 views)
Reply With Quote
  #6  
Old 08-21-2022, 09:48 PM
Guessed's Avatar
Guessed Guessed is offline Need help deleting some specific files by an Excel macro Windows 10 Need help deleting some specific files by an Excel macro Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,932
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

The Kill command is being passed a filename but it doesn't know what path that file is sitting in. You might have more luck if you add that path in to the Kill command

Code:
Kill "D:\kalantari\miscellaneous\dailyreport01\" & MyFiles
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #7  
Old 08-22-2022, 08:04 PM
soroush.kalantari soroush.kalantari is offline Need help deleting some specific files by an Excel macro Windows 10 Need help deleting some specific files by an Excel macro Office 2016
Competent Performer
Need help deleting some specific files by an Excel macro
 
Join Date: Jun 2021
Posts: 115
soroush.kalantari is on a distinguished road
Default

Quote:
Originally Posted by Guessed View Post
The Kill command is being passed a filename but it doesn't know what path that file is sitting in. You might have more luck if you add that path in to the Kill command

Code:
Kill "D:\kalantari\miscellaneous\dailyreport01\" & MyFiles
Thank you very much. It worked and solved the problem.
Reply With Quote
Reply

Tags
delete files

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Need help deleting some specific files by an Excel macro Word macro for deleting a line that starts with a specific character + deleting the line before eduardb Word 1 08-10-2022 03:17 AM
Need help deleting some specific files by an Excel macro Excel Macro finding a specific word ducky831 Excel Programming 3 09-17-2015 01:36 PM
Need help deleting some specific files by an Excel macro Excel VBA Macro - Deleting Specific Data based on criteria MD011 Excel Programming 3 12-10-2014 02:15 AM
Need help deleting some specific files by an Excel macro Macro to copy specific columns in Excel from another spreadsheet KD999 Excel Programming 1 07-20-2012 08:58 AM
excel 2010 not deleting tmp files on save/close willbaker13 Excel 0 04-26-2012 05:08 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 03:22 AM.


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