How to save file same name and diferrent extension in another folder ? (VBA)

rodrigo_m_almeida

New Member
Joined
Jan 13, 2022
Messages
42
Office Version
  1. 2021
Platform
  1. Windows
Good afternoon !

I'm using this code :

VBA Code:
Public Sub TEST()

    Application.ScreenUpdating = False
    
    Dim xPathName As String, xFileName As String, xActiveWorkbookName As String
    
    xPathName = "C:\ETC\CSV\"
    xFileName = Dir(xPathName & "*.csv")
    
    Do While Len(xFileName) > 0
    
        Workbooks.Open FileName:=xPathName & xFileName, ReadOnly:=True, UpdateLinks:=False
        
        xActiveWorkbookName = ActiveWorkbook.Name
        
        ActiveWorkbook.SaveAs "C:\ETC\EXCEL\" & ActiveWorkbook.Name & ".xlsx"
        
        Workbooks(xActiveWorkbookName).Close
        
        xFileName = Dir()
        
    Loop
    
    Application.ScreenUpdating = True

End Sub

I need to save with the same name in xlsx this csv file for another folder...
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
Is there a problem with that code? If so what?
 
Upvote 0
In that case use
VBA Code:
ActiveWorkbook.SaveAs "C:\ETC\EXCEL\" & ActiveWorkbook.Name & ".xlsx", 51
 
Upvote 0
You could try

VBA Code:
ActiveWorkbook.SaveAs "C:\ETC\EXCEL\" & replace(ActiveWorkbook.Name, ".csv", ".xlsx"), 51
 
Upvote 0
Solution
Ok, try
VBA Code:
        xActiveWorkbookName = Split(ActiveWorkbook.Name, ".")(0)
        
        ActiveWorkbook.SaveAs "C:\mrexcel\fluff\" & xActiveWorkbookName & ".xlsx", 51
        
       ActiveWorkbook.Close
 
Upvote 0
You could try

VBA Code:
ActiveWorkbook.SaveAs "C:\ETC\EXCEL\" & replace(ActiveWorkbook.Name, ".csv", ".xlsx"), 51
Ok, try
VBA Code:
        xActiveWorkbookName = Split(ActiveWorkbook.Name, ".")(0)
       
        ActiveWorkbook.SaveAs "C:\mrexcel\fluff\" & xActiveWorkbookName & ".xlsx", 51
       
       ActiveWorkbook.Close
Both work (y)

Now i have another problem
When the file is converted it breaks...

Before

before.PNG


After

after.PNG


Does anyone have any idea how I can fix this ?
 
Upvote 0
I think the problem is ", 51" file format number

Because depending on which I put it, it changes the way of displaying, none of them are similar to the old formatting that was
 
Upvote 0

Forum statistics

Threads
1,214,793
Messages
6,121,617
Members
449,039
Latest member
Mbone Mathonsi

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top