0

I'm trying to save a CSV file that can then be saved on any users desktop. I've been reading through a lot of threads, and I seem to be getting close, but just don't have the right mix!

The code below does exactly what I want...except it saves as a PDF rather than a CSV because it uses the exportasfixedformat object.

I think I need to use 'save as' for a CSV, but I cant work out how to then mix in the "userprofile" command to save regardless of user login.

Private Sub CommandButton1_Click() 

Sub SavePDF()     
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, _                   
          Filename:= Environ("USERPROFILE") & "\Desktop\Export.pdf", _        
          OpenAfterPublish:=True 
End Sub  
help-info.de
  • 6,695
  • 16
  • 39
  • 41
Alex
  • 1
  • 1
    Exporting as PDF as a fixed format or saving as csv is two very different things. Have a look [here](https://stackoverflow.com/q/10551353/9758194) – JvdV Oct 23 '19 at 12:16
  • Possible duplicate of [Save copies as .PDF & .xlsx](https://stackoverflow.com/questions/42068803/save-copies-as-pdf-xlsx) – help-info.de Oct 23 '19 at 12:19
  • Welcome to Stack Overflow! Please take the [tour](https://stackoverflow.com/tour) and read through the [help center](http://stackoverflow.com/help), in particular [how to ask](https://stackoverflow.com/help/how-to-ask). Your best bet here is to do your research, search for related topics on SO, and give it a go. After doing more research and searching, post a [Minimal, Complete, and Verifiable example](https://stackoverflow.com/help/mcve) of your attempt and say specifically where you're stuck, which can help you get better answers. – help-info.de Oct 23 '19 at 12:20

1 Answers1

0

This Should Work. Tested

Sub SaveCSVtoDesktop()

ActiveWorkbook.SaveAs Filename:=CreateObject("WScript.Shell").SpecialFolders("Desktop") & _
Application.PathSeparator & "Your File Name" & ".csv", FileFormat:=xlCSV, CreateBackup:=False

End Sub