Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6572657
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T15:02:03+00:00 2026-05-25T15:02:03+00:00

i wrote a macro for CSV to excel import for more then 65 k

  • 0

i wrote a macro for CSV to excel import for more then 65 k rows. I invoke the macro from c# through a button click.In the macro i wrote the code to read the text file line by line and add to the coloumn. Finally i select the whole coloumn and export to excel using enable “Text to coloumns” by comma seperated.

The problem is , it exports the first row only.

kindly help me.

Sub Read(FileName As String)
 'Dimension Variables
      Dim ResultStr As String
      'Dim FileName As String
      Dim FileNum As Integer
      Dim Counter As Double
      'Ask User for File's Name
      'FileName = InputBox("Please enter the Text File's name, e.g. test.txt")
      'Check for no entry
      If FileName = "" Then End
      'Get Next Available File Handle Number
      FileNum = FreeFile()
      'Open Text File For Input
      Open FileName For Input As #FileNum
      'Turn Screen Updating Off
      Application.ScreenUpdating = False
      'Create A New WorkBook With One Worksheet In It
      Workbooks.Add template:=xlWorksheet
      'Set The Counter to 1
      Counter = 1
      'Loop Until the End Of File Is Reached
      Do While Seek(FileNum) <= LOF(FileNum)
         'Display Importing Row Number On Status Bar
          Application.StatusBar = "Importing Row " & _
             Counter & " of text file " & FileName
          'Store One Line Of Text From File To Variable
          Line Input #FileNum, ResultStr
          'Store Variable Data Into Active Cell
          If Left(ResultStr, 1) = "=" Then
             ActiveCell.Value = "'" & ResultStr
          Else
             ActiveCell.Value = ResultStr
          End If

          'For xl97 and later change 16384 to 65536
          If ActiveCell.Row = 65536 Then
                ActiveWorkbook.ActiveSheet.Columns(1).Select
                Selection.TextToColumns DataType:=xlDelimited, _
                ConsecutiveDelimiter:=True, Space:=False, Comma:=True
                'If On The Last Row Then Add A New Sheet
                ActiveWorkbook.Sheets.Add
          Else
             'If Not The Last Row Then Go One Cell Down
             ActiveCell.Offset(1, 0).Select
          End If
          'Increment the Counter By 1
          Counter = Counter + 1
      'Start Again At Top Of 'Do While' Statement
      Loop
      'Close The Open Text File
      Close
      ActiveWorkbook.ActiveSheet.Columns(1).Select
      Selection.TextToColumns DataType:=xlDelimited, _
      ConsecutiveDelimiter:=True, Space:=False, Comma:=True
      'Remove Message From Status Bar
      Application.StatusBar = False
End Sub

C sharp Button click event,

private void button1_Click(object sender, EventArgs e)
        {
            file_Writer = new StreamWriter(@"c:\tstf.csv",true);
            //file_Writer.Close();
            //first row
            for (int i = 0; i < 8; i++)
            {
                file_Writer.Write("A,");
            }
            file_Writer.Write("\n");


            // second row

            for (int i = 0; i < 8; i++)
            {
                file_Writer.Write("B,");
            }

            file_Writer.Close();

            Thread.Sleep(1000);


            object oMissing = System.Reflection.Missing.Value;

            Excel.ApplicationClass oExcel = new Excel.ApplicationClass();
            oExcel.Visible = true;
            Excel.Workbooks oBooks = oExcel.Workbooks;
            Excel._Workbook oBook = null;
            oBook = oBooks.Open("F:\\read.xls", oMissing, oMissing,
                oMissing, oMissing, oMissing, oMissing, oMissing, oMissing,
                oMissing, oMissing, oMissing, oMissing, oMissing, oMissing);

            // Run the macros.
            //RunMacro(oExcel, new Object[] { "DoKbTest" });
            RunMacro(oExcel, new Object[] { "siva1", @"c:\tstf.csv" });


            // Quit Excel and clean up.
            oBook.Close(false, oMissing, oMissing);
            System.Runtime.InteropServices.Marshal.ReleaseComObject(oBook);
            oBook = null;
            System.Runtime.InteropServices.Marshal.ReleaseComObject(oBooks);
            oBooks = null;
            oExcel.Quit();
            System.Runtime.InteropServices.Marshal.ReleaseComObject(oExcel);
            oExcel = null;


            GC.Collect();
        }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T15:02:03+00:00Added an answer on May 25, 2026 at 3:02 pm

    I found the cause of problem . This is due to carriage return “\n”. I add the “\r\n” at the end of line instead of “\n” only.

    file_Writer.Write("\r\n");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wrote an Excel VBA macro to do conditional formatting using an intersect of
I'm want use $ macro in groovy GString. When i'm wrote this code ['cdata','tdata'].each
I'm trying to write an Excel macro using VBA to automate importing CSV text
I wrote a macro that imports a CSV file into my spreadsheet, using a
I wrote macro in Excel that uses dynamic array. Users will add elements to
I wrote the macro in Excel and want to distribute it to the users.
I wrote VBA code that updates changes made in Excel to a database (SQL
I have a macro that I wrote to just help me with my unit
I wrote a macro as an add-in, and I need to get the path
I wrote a debug macro that prints to the console the passed-in string whenever

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.