Hello
We're having an issue with a simple piece of VBA code which we are using to export a couple of sheets from an MS Excel workbook as CSV files. The code works perfectly on my PC and one other, but on two other people's PCs it fails to save the two CSV files. I have stepped through the code piece by piece on one of the failing PCs and everything seems to work, up until the line where the "SaveAs" method is called. There are no error messages given, and the files don't save.
We are all using MS 365 for Business - version info as follows: Microsoft® Excel® for Microsoft 365 MSO (Version 2209 Build 16.0.15629.20200) 64-bit.
The files are being saved to a shared OneDrive folder. Thinking it was a OneDrive sync issue we tested it on a failing PC in their C: drive - still no success. Code is below - thanks in advance!
We're having an issue with a simple piece of VBA code which we are using to export a couple of sheets from an MS Excel workbook as CSV files. The code works perfectly on my PC and one other, but on two other people's PCs it fails to save the two CSV files. I have stepped through the code piece by piece on one of the failing PCs and everything seems to work, up until the line where the "SaveAs" method is called. There are no error messages given, and the files don't save.
We are all using MS 365 for Business - version info as follows: Microsoft® Excel® for Microsoft 365 MSO (Version 2209 Build 16.0.15629.20200) 64-bit.
The files are being saved to a shared OneDrive folder. Thinking it was a OneDrive sync issue we tested it on a failing PC in their C: drive - still no success. Code is below - thanks in advance!
VBA Code:
Sub ExportAsCSV()
Dim MyFileName As String
Dim CurrentWB As Workbook, TempWB As Workbook
Set CurrentWB = ActiveWorkbook
ActiveWorkbook.ActiveSheet.UsedRange.Copy
Set TempWB = Application.Workbooks.Add(1)
With TempWB.Sheets(1).Range("A1")
.PasteSpecial xlPasteValues
.PasteSpecial xlPasteFormats
End With
MyFileName = CurrentWB.Path & "\" & CurrentWB.ActiveSheet.Name & ".csv"
Application.DisplayAlerts = False
TempWB.SaveAs Filename:=MyFileName, FileFormat:=xlCSV, CreateBackup:=False, Local:=True
TempWB.Close SaveChanges:=False
Application.DisplayAlerts = True
End Sub
Last edited by a moderator: