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

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
83,148
Office Version
  1. 365
Platform
  1. Windows
Is there a problem with that code? If so what?
 
Upvote 0

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
83,148
Office Version
  1. 365
Platform
  1. Windows
In that case use
VBA Code:
ActiveWorkbook.SaveAs "C:\ETC\EXCEL\" & ActiveWorkbook.Name & ".xlsx", 51
 
Upvote 0

JEC

Well-known Member
Joined
Aug 21, 2021
Messages
1,188
Office Version
  1. 365
Platform
  1. Windows
You could try

VBA Code:
ActiveWorkbook.SaveAs "C:\ETC\EXCEL\" & replace(ActiveWorkbook.Name, ".csv", ".xlsx"), 51
 
Upvote 0
Solution

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
83,148
Office Version
  1. 365
Platform
  1. Windows
Ok, try
VBA Code:
        xActiveWorkbookName = Split(ActiveWorkbook.Name, ".")(0)
        
        ActiveWorkbook.SaveAs "C:\mrexcel\fluff\" & xActiveWorkbookName & ".xlsx", 51
        
       ActiveWorkbook.Close
 
Upvote 0

rodrigo_m_almeida

New Member
Joined
Jan 13, 2022
Messages
42
Office Version
  1. 2021
Platform
  1. Windows
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

rodrigo_m_almeida

New Member
Joined
Jan 13, 2022
Messages
42
Office Version
  1. 2021
Platform
  1. Windows
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,191,054
Messages
5,984,384
Members
439,883
Latest member
onions44

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
Top