title: Want to run sql file through VBA
body: <p>I am trying to connect to the Sybase server through VBA and run the sql file that contains a set of sql lines (sometimes more than 60 lines).</p>
  
  <p>I have written the code as below. However, it is giving me error that " There is an incorrect statement around '\'"</p>
  
  <p>Please help.</p>
  
  <pre><code>Sub sqltest()
  
  Dim conn As ADODB.Connection
  Dim cmd As ADODB.Command
  
  Set conn = New ADODB.Connection
  conn.Open "DRIVER={Sybase ASE ODBC Driver};UID=" &amp; ThisWorkbook.Sheets("Sheet1").Cells(2, 13).Value &amp; ";pwd=" &amp; ThisWorkbook.Sheets("Sheet1").Cells(2, 14).Value &amp; ";NA=&lt;server address&gt; ; CommandTimeout = 50000 ;ConnectionTimeout = 50000; ConnectionIdleTimeout = 50000;Connection LifeTime = 50000;LoginTimeout = 50000;AlternateServers = &lt;server address&gt;;"
  conn.Open
  
  Set cmd = New ADODB.Command
  cmd.ActiveConnection = conn
  cmd.CommandType = adCmdStoredProc
  cmd.CommandText = "\\&lt;IP address&gt;\pag\OffShore PAG\Parallel Run\Reports\Sunil\Mymacros\sample macros\SQL NC DB.sql"
  
  cmd.Execute
  conn.Close
  
  Set conn = Nothing
  Set cmd = Nothing
  
  End Sub
  </code></pre>