Forum Discussion
YannickDVTC
Aug 31, 2022Copper Contributor
Change Macro path for any user of company
Hi all, I am currently working with a macro which export a sheet as a CSV to file (shared with all the company thanks to onedrive). The macro is working, but as I have to share the file with col...
DexterG_III
Aug 31, 2022Iron Contributor
YannickDVTC this is the code I use for this situation (refer to lines 14,15, & 18 for the syntax).
Hopefully this will work for you.
Sub CSVExport()
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
Set ObjWshNw = CreateObject("WScript.Network")
CurUser = ObjWshNw.UserName
'Dim Change below to "- 4" to become compatible with .xls files
MyFileName = "C:\Users\" & CurUser & "\Template Article Creation\CSV Supplier\Article Creation_" & _
Range("GA2") & _
Format(Date, "_ddmmyy_") & _
Format(Time, "hmmss") & ".csv"
Application.DisplayAlerts = False
TempWB.SaveAs Filename:=MyFileName, FileFormat:=xlCSV, CreateBackup:=False, Local:=True
TempWB.Close SaveChanges:=False
Application.DisplayAlerts = True
End Sub