I have 4 files in a folder and want to use VBA to rename and change file type
CSV to XLSX
Please see attached excel workbook
Thanks Carroll
I have 4 files in a folder and want to use VBA to rename and change file type
CSV to XLSX
Please see attached excel workbook
Thanks Carroll
See next code
![]()
Please Login or Register to view this content.
- Battle without fear gives no glory - Just try
Thanks PCI
I made some changes
CURRENTfolder = "c:\# CURRENT RIBBSTEST AUTOMATING\"
commented out XlsFolder = "C:\Users\user\Downloads\JOB7\" I want to stay in "c:\# CURRENT RIBBSTEST AUTOMATING\" and then kill all "csv" files, leaving only the xlsx files
My changes don't work - stops in the first if statement - don't understand why?
Thanks for your help
Option Explicit
Sub Macro1()
Dim CURRENTfolder As String
Dim XlsFolder As String
Dim fname As String
Dim wBook As Workbook
Dim COUNTER As Long
COUNTER = 1
CURRENTfolder = "c:\# CURRENT RIBBSTEST AUTOMATING\"
' XlsFolder = "C:\# CURRENT RIBBSTEST AUTOMATING\"
fname = Dir(CURRENTfolder & "*.csv")
Do While fname <> ""
Set wBook = Workbooks.Open(CURRENTfolder & fname, Format:=6, DELIMITER:=",")
If COUNTER = 1 Then _
ActiveWorkbook.SaveAs Filename:=CURRENTfolder & "DALLAS.xlsx" _
, FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False
If COUNTER = 2 Then _
ActiveWorkbook.SaveAs Filename:=CURRENTfolder & "FRISCO.xlsx" _
, FileFormat:=xlOpenXMLWorkbook
If COUNTER = 3 Then _
ActiveWorkbook.SaveAs Filename:=CURRENTfolder & "MCKINNEY.xlsx" _
, FileFormat:=xlOpenXMLWorkbook
If COUNTER = 4 Then _
ActiveWorkbook.SaveAs Filename:=CURRENTfolder & "RICHARDSON.xlsx" _
, FileFormat:=xlOpenXMLWorkbook
wBook.Close False
fname = Dir
COUNTER = COUNTER + 1
Loop
Kill CURRENTfolder & "*.csv"
End Sub
You forgot the code tags : Just select the code and clic on the # icon
Where the code stops?
Next statement
must be![]()
Please Login or Register to view this content.
no ' at the beginning![]()
Please Login or Register to view this content.
PCI thanks for your patience
These lines in your code
CURRENTfolder = "C:\Users\user\Downloads\JOB7\"
XlsFolder = "C:\Users\user\Downloads\JOB7\"
the files I want to rename are in folder "C:\# CURRENT RIBBSTEST AUTOMATING\"
so shouldn't my code be
CURRENTfolder = "C:\# CURRENT RIBBSTEST AUTOMATING\"
XlsFolder = "C:\# CURRENT RIBBSTEST AUTOMATING\"
Also I want to put the code in commandbutton 3 not a macro
can I just copy your code - starting with the line Dim CURRENTfolder As String
carroll
Also, I don't understand your instructions...
You forgot the code tags : Just select the code and clic on the # icon
Where the code stops?
Next statement
When I select your code I don't see a # icon where the code stops
carroll
so shouldn't my code beYes and it was not like that there was a ===> ' at the beginning of the last one![]()
Please Login or Register to view this content.
YEScan I just copy your code - starting with the line Dim CURRENTfolder As String
Just above the window where you write you answer or thread there is a ribbon with 17 iconsAlso, I don't understand your instructions...
You forgot the code tags : Just select the code and clic on the # icon
Where the code stops?
Next statement
When I select your code I don't see a # icon where the code stops
See file attached
Last edited by PCI; 12-28-2019 at 07:00 PM.
Possibly...![]()
Please Login or Register to view this content.
Last edited by dangelor; 12-28-2019 at 07:35 PM. Reason: previous sub failed
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks