title: Default path in Excel using VBA
body: <p>The goal is to automate a daily task to open a workbook, import .csv files and perform some formatting, save, and exit excel, the only requirement being the computer is on.  I'm using the windows task scheduler to open a macro enabled workbook on a daily basis.  With help from this site, I added the argument /p "my specific path" to the task to set the import path I wish to access.  Then, using the Workbook_open function, the import is performed, however, the following error occurs while highlighting the .refresh backgroundquery:=false line:</p>
  
  <pre><code>Run-time error '1004':
  Excel cannot find the text file to refresh this external data range.
  Check to make sure the text file has not been moved or renamed, then try
    the refresh again.
  </code></pre>
  
  <p>Now, if I select "End" to stop the debugger and simply run the macro on my own, everything works fine.  The path is on a network, if that matters.  I can post parts of the code if that would help, but it's pretty long.
  It goes without saying I'm no VBA whiz, so I've pieced the code together,but everything works except the initial import of the .csv file.
  Thanks in advance for any advice.</p>
  
  <p>Relevant code:</p>
  
  <pre><code>R = 1
  FName = Dir(Path &amp; DayTime &amp; ".csv")
  
  Do While FName &lt;&gt; ""
      ImportCsvFile FName, ActiveSheet.Cells(R, 1)
      R = ActiveSheet.UsedRange.Rows.count + 1
      DayTime = DayTime + 1
      FName = Dir(Path &amp; DayTime &amp; ".csv")
  Loop
  
  Sub ImportCsvFile(FileName As Variant, Position As Range)
  With ActiveSheet.QueryTables.Add(Connection:= _
    "TEXT;" &amp; FileName _
    , Destination:=Position)
    .Name = Replace(FileName, ".csv", "")
    .FieldNames = True
    .RowNumbers = False
    .FillAdjacentFormulas = False
    .RefreshOnFileOpen = False
    .BackgroundQuery = True
    .RefreshStyle = xlInsertDeleteCells
    .SavePassword = False
    .SaveData = True
    .AdjustColumnWidth = True
    .TextFilePromptOnRefresh = False
    .TextFilePlatform = xlMacintosh
    .TextFileStartRow = 1
    .TextFileParseType = xlDelimited
    .TextFileTextQualifier = xlTextQualifierDoubleQuote
    .TextFileConsecutiveDelimiter = False
    .TextFileTabDelimiter = True
    .TextFileSemicolonDelimiter = False
    .TextFileCommaDelimiter = False
    .TextFileSpaceDelimiter = False
    .TextFileOtherDelimiter = ","
    .TextFileColumnDataTypes = Array(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)
    .Refresh BackgroundQuery:=False
  End With
  End Sub
  </code></pre>