title: Pasting data from text file to excel using VB 2010 express
body: <p>This may sound very easy but I am a newbie in vb programming. I have a text file with 11 rows, 2 columns separated by 39 spaces between them. Now I'm trying to read this file, copy it &amp; paste into an excel sheet. Here is the code that I have so far:</p>
  
  <pre><code>Imports System.IO
  
  Public Class Form1
  
      Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
          Dim oExcel As Object
          Dim oBook As Object
          Dim oRow As Int16 = 0
  
          oExcel = CreateObject("Excel.Application")
          oBook = oExcel.Workbooks.Add
  
          'Read input .txt file line-by-line, Copy to Clipboard &amp; Paste to Excel
  
          Using rdr As New System.IO.StreamReader("C:\Temp\ONI.txt")
              Do While rdr.Peek() &gt;= 0
                  Dim InputLine As String = rdr.ReadLine
                  oRow = oRow + 1
                  System.Windows.Forms.Clipboard.SetDataObject (InputLine)
                  oBook.Worksheets(1).Range("A" + oRow.ToString).Select()
                  oBook.Worksheets(1).Paste()
              Loop
              rdr.Close()
          End Using
  
          oExcel.Visible = True
          'oExcel.SaveAs("C\Temp\test.xls")
          oBook = Nothing
          oExcel.Quit()
          oExcel = Nothing
      End Sub
  
  End Class
  </code></pre>
  
  <p>This is working to the extent that an excel workbook is opened &amp; the data is getting pasted in A1 to A11 i.e the rows are 11 (which is ok) but the column is only 1 (it should be in columns A &amp; B). I know this is very easy, please guide me. </p>
  
  <p>Also the code stops at the "Save as" line (which I have commented). When run it shows error <code>Public member 'SaveAs' on type 'ApplicationClass' not found.</code></p>