Sharepoint folder Excel files convert to csv files

Mira_Xcel

New Member
Joined
May 25, 2020
Messages
2
Office Version
  1. 365
Platform
  1. Windows
Hello VBA experts,

There is a wonderful code that I would like to reuse. Could you please help me to amend the code to open xls files in a SharePoint folder and save in the same SharePoint folder csv files?

Many thanks and kind regards
Mira Abel


Option Explicit
Sub ConvertToCSV()

'The following has been adapted from here:
'https://msdn.microsoft.com/en-us/vba/excel-vba/articles/application-filedialog-property-excel


Dim lngCount As Long
Dim objFSO As Object

Application.ScreenUpdating = False

Set objFSO = CreateObject("Scripting.FileSystemObject")

With Application.FileDialog(msoFileDialogOpen)
.InitialFileName = "D:\Robert\USB Backup 18-Jan-2018\ROB'S USB\Excel\Samples\" 'Initial file path. Don't forget trailing backslash.
'Add a custom filter to list Excel files only
With .Filters
.Clear
.Add "Excel Files Only", "*.xls*"
End With
.AllowMultiSelect = True
.Show
'Loop through each file selected, converting them to a CSV format.
'//Note that as a *.csv file can only have a single tab the sheet the *.xls*' workbook opens on will be the *.csv file//
For lngCount = 1 To .SelectedItems.Count
'Open Workbook
Workbooks.Open Filename:=.SelectedItems(lngCount)
'Turn alters off
Application.DisplayAlerts = False
'Save the active tab as a *.csv file
ActiveWorkbook.SaveAs Filename:=objFSO.GetParentFolderName(.SelectedItems(lngCount)) & "\" & objFSO.GetBaseName(.SelectedItems(lngCount)) & ".csv", FileFormat:=xlCSV, CreateBackup:=False
ActiveWorkbook.Close False
Application.ScreenUpdating = True
Next lngCount
End With

Set objFSO = Nothing

Application.ScreenUpdating = True

End Sub
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.

severynm

Active Member
Joined
Jan 8, 2021
Messages
273
Office Version
  1. 365
Platform
  1. Windows
Have you synced said SharePoint folder to your computer? If so, the only thing you should have to change is the initial folder path, to something like C:\Users\%localusername%\SharePointCompanyName\SharePointFolders\.
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,152,044
Messages
5,767,800
Members
425,437
Latest member
blaix

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