Library code snippets

Converting an Excel file to Tab Delimited Format

This code will convert an Excel file to tab delimited format, using the Excel object model (which will require Excel to be installed where this code is run!).

Dim lobjExcel As Object  ' Instance Of The Excel Application Object
Dim lobjWorkBook As Object         'Instance For WorkBook Collection
Set lobjExcel = server.CreateObject("Excel.Application")
Set lobjWorkBook = lobjExcel.Workbooks.Open(Filename with the path)
lobjExcel.DisplayAlerts = False
'Saving In The Tab Delimited Format
lobjWorkBook.SaveAs lstrFilePath, -4158
lobjWorkBook.Close
Set lobjWorkBook = Nothing
'DesTroying The Excel Object
lobjExcel.Quit
lobjExcel = Nothing

Comments

  1. 28 Sep 2007 at 21:54

    This -4158 reference is pretty bad practice.

    If you have added the Excel Object Model to your projects, then you should use the predefined constants for fileformat.

    Thse appear as a drop down set of options when you just type in

    XlFileFormat.

    -4158 is the actual value of  XLFileFormat.xlCurrentPlatformText 

    Other values are:

    xlCSV  (which has a value of 6)

    xlHTML (value 44)

    but the point is if the code had actually said xlCurrentPlatformText  instead of -4158, then many of the messages  asking 'where did you get that number from?'  would not have been posted.

     

    You can find the constants available from any object library by pressing F2 and examining the object model there.

     

     

  2. 15 Jun 2007 at 14:55
    Bob Day wrote:
    Thanks, Vipin - could you share where you got the  -4158 reference for the FileFormat property? Can you tell me where to find this reference?
  3. 07 Oct 2006 at 07:38

    Guys i need help in tab delimited format... im a newbieand ,i dont have any idea in this thing.. can someone post a visual basic program code that uses "tab delimited "or a .txt file in storing data...

    Name        Age           Address

    xxxx         xx              xxxxxxxxxxxxx

    xxxx         xx              xxxxxxxx

    i want to learn how to save data, get data, update data..

    i need to learn this because saving and getting records into a txt file will reduce processing time....

    Thank you so much...hoping for ur reply...thankz...XP

     

  4. 11 Jul 2006 at 04:08
    Thanks, Vipin - could you share where you got the  -4158 reference for the FileFormat property?

  5. 19 Jan 2006 at 17:26

    Hi Vipin,


    Thanks for the great piece of code. Just a hint can you let people know that in the code where you've placed the word


    lobjWorkBook.SaveAs lstrFilePath, -4158


    'lstrFilePath' is the name of the output txt file.


    Thanks for helping me out your a super-hero!


    Eddy

  6. 01 Jan 1999 at 00:00

    This thread is for discussions of Converting an Excel file to Tab Delimited Format.

Leave a comment

Sign in or Join us (it's free).

Vipin Mohandas

We'd love to hear what you think! Submit ideas or give us feedback