0

I have having issues working out how to save a file without using full length file paths... As I am using the excel namespace the default save directs to documents, rather than the project directory.

Here is what I have been trying :

Private Sub createStationsCSV(ByRef station As String)
    Dim appXL As Excel.Application = CreateObject("Excel.Application")
    'appXL.DefaultFilePath = "C:\Users\****\source\repos\FQR Generator\FQR Generator\bin\Debug\"
    Dim wbXL As Excel.Workbook
    Dim shXL As Excel.Worksheet
    ' Dim raXL As Excel.Range
    wbXL = appXL.Workbooks.Add
    shXL = wbXL.ActiveSheet
    wbXL.SaveAs("FQR Generator Data\Stations\" & station)
    appXL.Quit()

End Sub
BigBen
  • 46,229
  • 7
  • 24
  • 40
dkettle01
  • 3
  • 3
  • If you deploy the program into users' "Program Files" directories, it won't be able to save there - it's a Windows anti-malware security measure. You could use `Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "FQR Generator Data\Stations\", station)` as the save location instead. – Andrew Morton Jun 05 '20 at 15:58
  • Why are you passing `station` `ByRef`? – Mary Jun 05 '20 at 16:29
  • 1
    @Mary It will be changed in the sub once fully done – dkettle01 Jun 05 '20 at 17:49
  • 1
    @AndrewMorton This was the issue, your help is appreciated :) – dkettle01 Jun 05 '20 at 17:52
  • 1
    @dkettle01 You're welcome :) In that case, this question is a duplicate of [Where to save application data in .NET application](https://stackoverflow.com/questions/4650209/where-to-save-application-data-in-net-application). – Andrew Morton Jun 05 '20 at 17:59
  • Recommend you look at using EPPlus rather than excel interop to create your file – Caius Jard Jun 05 '20 at 22:11

0 Answers0