+ Reply to Thread
Results 1 to 5 of 5

Delete type (xls) specific file in folder

  1. #1
    Registered User
    Join Date
    01-22-2013
    Location
    Kl, Malaysia
    MS-Off Ver
    Excel 2010
    Posts
    35

    Delete type (xls) specific file in folder

    Hi

    I am using Kill "[folder directory]" & "*.xls" to delete all the .xls type file in the folder but the code also delete file type .xlsx and .xlsm

    Below are my code.

    Please help. Thank you.

    Sub ConvertXlsToXlsx()

    Application.ScreenUpdating = False

    Dim strPath As String
    Dim strFile As String
    Dim wbk As Workbook
    ' Path must end in trailing backslash
    strPath = Range("Convert_Location") & "\"
    strFile = Dir(strPath & "*.xls")
    Do While strFile <> ""
    If LCase(Right(strFile, 3)) = "xls" Then

    Set wbk = Workbooks.Open(Filename:=strPath & strFile)

    If wbk.HasVBProject Then
    wbk.SaveAs Filename:=strPath & strFile & "m", _
    FileFormat:=xlOpenXMLWorkbookMacroEnabled
    Else
    wbk.SaveAs Filename:=strPath & strFile & "x", _
    FileFormat:=xlOpenXMLWorkbook
    End If
    wbk.Close SaveChanges:=False
    End If
    strFile = Dir

    Loop

    On Error Resume Next
    Kill strPath & "*.xls"
    On Error GoTo 0


    MsgBox "This VBApp has completed its task." & vbNewLine & vbNewLine & "Please find the converted file(s) in the same folder."

    End Sub

  2. #2
    Forum Guru :) Sixthsense :)'s Avatar
    Join Date
    01-01-2012
    Location
    India>Tamilnadu>Chennai
    MS-Off Ver
    2003 To 2010
    Posts
    12,770

    Re: Delete type (xls) specific file in folder

    Refer the below link:-

    https://stackoverflow.com/questions/...fied-extension


    If your problem is solved, then please mark the thread as SOLVED>>Above your first post>>Thread Tools>>
    Mark your thread as Solved


    If the suggestion helps you, then Click *below to Add Reputation

  3. #3
    Forum Expert Pepe Le Mokko's Avatar
    Join Date
    05-14-2009
    Location
    Belgium
    MS-Off Ver
    O365 v 2402
    Posts
    13,448

    Re: Delete type (xls) specific file in folder

    Administrative Note:

    Welcome to the forum.

    We would very much like to help you with your query, however you need to include code tags around your code.

    Please take a moment to add the tags. Posting code between [CODE]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/CODE] tags makes your code much easier to read and copy for testing, and it also maintains VBA formatting.

    Please see Forum Rule #2 about code tags and adjust accordingly. Click on Edit to open your post, then highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here

    (Note: this change is not optional. No help to be offered until this moderation request has been fulfilled.)

  4. #4
    Registered User
    Join Date
    01-22-2013
    Location
    Kl, Malaysia
    MS-Off Ver
    Excel 2010
    Posts
    35

    Re: Delete type (xls) specific file in folder

    Ok thanks. Will do next time.

  5. #5
    Registered User
    Join Date
    01-22-2013
    Location
    Kl, Malaysia
    MS-Off Ver
    Excel 2010
    Posts
    35

    Re: Delete type (xls) specific file in folder

    Quote Originally Posted by :) Sixthsense :) View Post
    Thanks a lot I got my own solutions.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Copy worksheet 1 from the first file in a folder then delete the file
    By zed369 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-29-2019, 01:14 AM
  2. Macro to move a specific type file one folder level up.
    By karthikiyer2k in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-31-2018, 12:47 PM
  3. [SOLVED] Open newest folder and specific file in the folder
    By timtim91 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-09-2017, 11:55 AM
  4. [SOLVED] Save as xlsm file with specific name & specific folder
    By namialus in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-07-2015, 03:32 AM
  5. Delete old files in a specific folder
    By forfiett in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 09-26-2014, 02:37 AM
  6. [SOLVED] save macro with specific folder and file name and type
    By wolfm in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-25-2013, 10:08 AM
  7. Delete Specific type of chart from active sheet
    By Macdave_19 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-20-2009, 06:42 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1