Excel VBA Course
Excel VBA Course - From Beginner to Expert

200+ Video Lessons
50+ Hours of Video
200+ Excel Guides

Become a master of VBA and Macros in Excel and learn how to automate all of your tasks in Excel with this online course. (No VBA experience required.)

View Course

delete files XLS after convert to XLSM

0

hello

I  have   this  code  works  well . it  converts  files are  .XLS to  XLSM  ,but   what  I'm looking  for it    . it  should  delete   all   the  files  are .XLS   after  convering  to XLSM .

Sub TrandformAllXLSFilesToXLSM()
Dim myPath As String

myPath = "C:\Users\alhagag\Desktop\MACROS\"
WorkFile = Dir(myPath & "*.xls")

Do While WorkFile <> ""
    If Right(WorkFile, 4) <> "xlsm" Then
        Workbooks.Open Filename:=myPath & WorkFile
        ActiveWorkbook.SaveAs Filename:= _
        myPath & WorkFile & "m", FileFormat:= _
        xlOpenXMLWorkbookMacroEnabled, CreateBackup:=False
        ActiveWorkbook.Close
     End If
     WorkFile = Dir()
Loop

End Sub
 

any  suggestion  to  do  that ,please?

Answer
Discuss

Answers

0
Selected Answer

Hi Leap,

Here you go:-

Sub TrandformAllXLSFilesToXLSM()
    ' 274

    Dim myPath      As String
    Dim WorkFile    As String

    myPath = "C:\Users\alhagag\Desktop\MACROS\"
    WorkFile = Dir(myPath & "*.xls")

    Application.DisplayAlerts = False
    Do While WorkFile <> ""
        If Right(WorkFile, 4) <> "xlsm" Then
            Workbooks.Open Filename:=myPath & WorkFile
            With ActiveWorkbook
                WorkFile = .FullName
                .SaveAs Filename:=WorkFile & "m", _
                        FileFormat:=xlOpenXMLWorkbookMacroEnabled, _
                        CreateBackup:=False
                .Close
            End With
            Kill WorkFile
         End If
         WorkFile = Dir()
    Loop
    Application.DisplayAlerts = True
End Sub
Discuss

Discussion

Leopard  not Leap 
thanks   very  much   for  your  answering 
leopard (rep: 88) Jul 3, '21 at 2:13 am
Sorry, Leopard. I'll be more attentive next time. See you again soon :-)
Variatus (rep: 4889) Jul 3, '21 at 3:12 am
Add to Discussion


Answer the Question

You must create an account to use the forum. Create an Account or Login