I am using a VBA macro button to export a range of cells as a CSV file to the desktop. This file will be downloaded on multiple computers so I want the macro to save to the desktop regardless of which computer it is downloaded on.
This is the code for my macro and when I do it on my laptop, the computer that I created the files on, it works; however, when any of my coworkers do it the CSV file isn't auto saved to the desktop but instead it is opened with Excel and these errors populate. I could just change the directions so that instead of just pressing the export button that they press it, save the file themselves, and then use it but I want to automate this as much as possible. Any ideas why I receive these errors on other laptops but not mine?
Someone suggested using
But I am unsure of how to incorporate that into my current code.
VBA Code:
Sub seetest()
Const CSVDATA = "B1:IG2"
Dim ws As Worksheet, filename As String
filename = "C:\Users\" & Environ("Username") & _
"\Desktop\Labels " & Format(Date, "YYYY-MM-DD") & ".csv"
Set ws = ThisWorkbook.ActiveSheet
With Workbooks.Add(1)
ws.Range(CSVDATA).Copy .Sheets(1).Range("A1")
.SaveAs filename, xlCSV
.Close
End With
MsgBox CSVDATA & " exported to " & filename, vbInformation
End Sub
This is the code for my macro and when I do it on my laptop, the computer that I created the files on, it works; however, when any of my coworkers do it the CSV file isn't auto saved to the desktop but instead it is opened with Excel and these errors populate. I could just change the directions so that instead of just pressing the export button that they press it, save the file themselves, and then use it but I want to automate this as much as possible. Any ideas why I receive these errors on other laptops but not mine?
Someone suggested using
VBA Code:
"C:\Users\" & Environ("Username") & "\Desktop\ "? Does Environ("Username")
But I am unsure of how to incorporate that into my current code.