3

I have this code.

This code converts to xlsm files.

I want to convert to xlsx files.

How?

I tried by changing

wBook.SaveAs XlsFolder & Replace(fname, ".csv", ""), ThisWorkbook.FileFormatTO wBook.SaveAs XlsFolder & Replace(fname, ".csv", ".xlsx") 

It didn't worked.

Private Sub CommandButton2_Click() Dim CSVfolder As String Dim XlsFolder As String Dim fname As String Dim wBook As Workbook CSVfolder = "C:\csv\" XlsFolder = "C:\Charts\" fname = Dir(CSVfolder & "*.csv") Do While fname <> "" Set wBook = Workbooks.Open(CSVfolder & fname, Format:=6, Delimiter:=",") wBook.SaveAs XlsFolder & Replace(fname, ".csv", ""), ThisWorkbook.FileFormat wBook.Close False fname = Dir Loop End Sub 

1 Answer 1

6

Using the macro recoder, the file format for an xlsx workbook is FileFormat:=xlOpenXMLWorkbook

So here is your code :

Private Sub CommandButton2_Click() Dim CSVfolder As String, _ XlsFolder As String, _ fname As String, _ wBook As Workbook CSVfolder = "C:\csv\" XlsFolder = "C:\Charts\" fname = Dir(CSVfolder & "*.csv") Do While fname <> "" Set wBook = Workbooks.Open(CSVfolder & fname, Format:=6, Delimiter:=",") wBook.SaveAs XlsFolder & Replace(fname, ".csv", ""), xlOpenXMLWorkbook wBook.Close False fname = Dir Loop End Sub 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.