Convert XLSX file to CSV through Invoke code method VBA, only change file type

Hello,

I am working on a unique case. Data has to be uploaded in a csv file format, but with a XLSX layout.

As in Cell A has data Cell B has data Cell C has data.

To do this manually, one can save a copy as and change the file type. I would like to do this without having to interface with the UI of Excel through the invoke code perspective.

I have found the thread on how to achieve this in reverse, but i was unable to reverse engineer it to meet this specific use case requirements.

Please provide guidance or useful links.

Hi @anthony.marrevee

You can read the xlsx file to a Data Table variable using Read Range Activity. Then write the data to a csv file using Write CSV Activity.

https://docs.uipath.com/activities/lang-en/docs/write-csv-file

Hi Kumar,

Unfortunately that method will not give the desired output in this scenario. As it uses the VB.net xlCSV format code and prints the results to the csv file.

In this specific case all that needs to change is the fileformat from xlsx → csv maintaining the data content distribution in the cells of the orginal xlsx file.

What i have been able to do is carry out this action through the UI. One alternative I was looking at is to use dataframe in pandas through invoke code activity.

Before relying on python I was hoping to find a more direct solution with the given scope of Uipath.

please follow the link

1 Like

Hi @anthony.marrevee

You can try this macro

Sub Macro1(OutputPath)

    ActiveWorkbook.SaveAs Filename:=OutputPath, _
        FileFormat:=xlCSVUTF8, CreateBackup:=False
End Sub

RunMacro.txt (138 Bytes)

XLSXToCSV.xaml (5.7 KB)

2 Likes

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.