Hi,
I'm trying to open n number of workbooks from a specific folder, delete rows 1 to 4 and then close the workbook, saving it as a .csv file. The format of the files is always the same and I'm using Excel 2007.
I have the following code:
Code
Sub OpenAndClearContentsInRows1to4()
Dim strF As String, strP As String
Dim wb As Workbook
Dim ws As Worksheet
'Declare folder name
strP = "C:\folder\"
strF = Dir(strP & "\*.xls") 'Type of files to look for
Do While strF <> vbNullString
Set wb = Workbooks.Open(strP & "\" & strF)
Set ws = wb.Sheets(1) 'use sheet 1 in all workbooks
ws.Range("A1:AA4").Delete
ActiveWindow.FreezePanes = False
ActiveWindow.SplitRow = False
ActiveWorkbook.SaveAs Filename:= _
(strP & "\*.csv") _
, FileFormat:=xlCSV, CreateBackup:=False
ActiveWorkbook.Save
ActiveWindow.Close
Loop
End Sub
Display More
The code above opens the workbooks and deletes the required rows, but what I'm struggling with is the part to save the workbook as csv and then close without prompting. Is there a function to do this?
Any advice would be greatly appreciated.
Many thanks,
Baron