title: Excel VBA to save file name as CSV and Cell Value
body: <p>I have a macro to export a range of cells to csv which is fine, I now need it to call the file as a cell value, preferably B2.</p>
  
  <p>Thanks in advance.</p>
  
  <p>Macro:</p>
  
  <pre><code>Sub WriteCSVFile()
  
      Dim My_filenumber As Integer Dim logSTR As String
  
      My_filenumber = FreeFile
  
      logSTR = logSTR &amp; Cells(2, "B").Value &amp; " , " 
      logSTR = logSTR &amp; Cells(3, "B").Value &amp; " , " 
      logSTR = logSTR &amp; Cells(4, "B").Value &amp; " , " 
      logSTR = logSTR &amp; Cells(5, "B").Value &amp; " , " 
      logSTR = logSTR &amp; Cells(6, "B").Value &amp; " , " 
      logSTR = logSTR &amp; Cells(7, "B").Value &amp; " , " 
      logSTR = logSTR &amp; Cells(8, "B").Value &amp; " , " 
      logSTR = logSTR &amp; Cells(9, "B").Value &amp; " , " 
      logSTR = logSTR &amp; Cells(10, "B").Value &amp; " , " 
      logSTR = logSTR &amp; Cells(11, "B").Value &amp; " , " 
      logSTR = logSTR &amp; Cells(12, "B").Value &amp; " , " 
      logSTR = logSTR &amp; Cells(13, "B").Value &amp; " , " 
      logSTR = logSTR &amp; Cells(14, "B").Value &amp; " , " 
      logSTR = logSTR &amp; Cells(15, "B").Value &amp; " , " 
      logSTR = logSTR &amp; Cells(16, "B").Value &amp; " , " 
      logSTR = logSTR &amp; Cells(18, "B").Value &amp; " , " 
      logSTR = logSTR &amp; Cells(19, "B").Value &amp; " , " 
      logSTR = logSTR &amp; Cells(20, "B").Value &amp; " , " 
      logSTR = logSTR &amp; Cells(21, "B").Value &amp; " , " 
      logSTR = logSTR &amp; Cells(22, "B").Value &amp; " , " 
      logSTR = logSTR &amp; Cells(23, "B").Value &amp; " , " 
      logSTR = logSTR &amp; Cells(24, "B").Value &amp; " , " 
      logSTR = logSTR &amp; Cells(25, "B").Value &amp; " , " 
      logSTR = logSTR &amp; Cells(26, "B").Value &amp; " , " 
      logSTR = logSTR &amp; Cells(27, "B").Value &amp; " , " 
      logSTR = logSTR &amp; Cells(28, "B").Value &amp; " , " 
      logSTR = logSTR &amp; Cells(29, "B").Value &amp; " , " 
      logSTR = logSTR &amp; Cells(30, "B").Value &amp; " , " 
      logSTR = logSTR &amp; Cells(31, "B").Value &amp; " , " 
      logSTR = logSTR &amp; Cells(32, "B").Value &amp; " , " 
      logSTR = logSTR &amp; Cells(33, "B").Value &amp; " , " 
      logSTR = logSTR &amp; Cells(35, "B").Value &amp; " , " 
      logSTR = logSTR &amp; Cells(36, "B").Value &amp; " , " 
      logSTR = logSTR &amp; Cells(37, "B").Value &amp; " , " 
      logSTR = logSTR &amp; Cells(38, "B").Value &amp; " , " 
      logSTR = logSTR &amp; Cells(39, "B").Value &amp; " , " 
      logSTR = logSTR &amp; Cells(40, "B").Value &amp; " , " 
      logSTR = logSTR &amp; Cells(41, "B").Value &amp; " , " 
      logSTR = logSTR &amp; Cells(42, "B").Value &amp; " , " 
      logSTR = logSTR &amp; Cells(45, "B").Value &amp; " , " 
      logSTR = logSTR &amp; Cells(46, "B").Value &amp; " , " 
      logSTR = logSTR &amp; Cells(47, "B").Value &amp; " , " 
      logSTR = logSTR &amp; Cells(48, "B").Value &amp; " , " 
      logSTR = logSTR &amp; Cells(49, "B").Value &amp; " , " 
      logSTR = logSTR &amp; Cells(50, "B").Value &amp; " , " 
      logSTR = logSTR &amp; Cells(51, "B").Value &amp; " , " 
      logSTR = logSTR &amp; Cells(52, "B").Value &amp; " , " 
      logSTR = logSTR &amp; Cells(54, "B").Value &amp; " , " 
      logSTR = logSTR &amp; Cells(55, "B").Value &amp; " , " 
      logSTR = logSTR &amp; Cells(56, "B").Value &amp; " , " 
      logSTR = logSTR &amp; Cells(57, "B").Value &amp; " , " 
      logSTR = logSTR &amp; Cells(58, "B").Value &amp; " , " 
      logSTR = logSTR &amp; Cells(59, "B").Value &amp; " , " 
      logSTR = logSTR &amp; Cells(60, "B").Value &amp; " , " 
      logSTR = logSTR &amp; Cells(61, "B").Value &amp; " , " 
      logSTR = logSTR &amp; Cells(62, "B").Value &amp; " , " 
      logSTR = logSTR &amp; Cells(63, "B").Value &amp; " , " 
      logSTR = logSTR &amp; Cells(64, "B").Value &amp; " , " 
      logSTR = logSTR &amp; Cells(66, "B").Value &amp; " , " 
      logSTR = logSTR &amp; Cells(67, "B").Value &amp; " , " 
      logSTR = logSTR &amp; Cells(68, "B").Value &amp; " , " 
      logSTR = logSTR &amp; Cells(69, "B").Value &amp; " , " 
      logSTR = logSTR &amp; Cells(70, "B").Value &amp; " , " 
      logSTR = logSTR &amp; Cells(71, "B").Value &amp; " , " 
      logSTR = logSTR &amp; Cells(72, "B").Value &amp; " , " 
      logSTR = logSTR &amp; Cells(73, "B").Value &amp; " , "
  
      Open "T:\Typing\Client Information\Test1.csv" For Append As
      #My_filenumber
          Print #My_filenumber, logSTR Close #My_filenumber
  
  End Sub
  </code></pre>