473,385 Members | 1,925 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Opening a space delimited textfile in Excel using VB.net

Hi everyone,
I'm having trouble opening space delimited textfiles in Excel from
Visual Basic.net. I'm able to control, open and modify Excel files
from Visual Basic, so my Excel reference seems to be working ok. I
just don't know what I'm doing when I try to open a space delimited
file and want to put the data into columns. I tried recording a macro
in VBA and going from there, but then I got stuff saying "Name
'xlDelimited' is not declared", etc. So then I started throwing
'Microsoft.Office.Interop.Excel.XLTextParsingType. xlDelimited' in front
because I saw that online somewhere, and things looked like they might
work, but alas, they did not. So here I am. If you haven't figured it
out yet, I'm not a programmer and I'm pretty new to VB, so I would
really appreciate some help on this. I've pasted the not-so-pretty
code I've attempted below solely for your amusement. To be honest, I'm
not even sure what about 90% of it means. With this code I get an
error saying something like "Expression does not produce a value".
Thanks for any help offered.

Dim oExcel As New Microsoft.Office.Interop.Excel.Application
Dim oBook As Object
Dim oSheet As Object

oExcel = CreateObject("Excel.Application")
oExcel.Visible = True
oBook = oExcel.Workbooks.OpenText("C:\TextTest.txt",
Origin:=437, StartRow:=1,
DataType:=Microsoft.Office.Interop.Excel.XlTextPar singType.xlDelimited,
TextQualifier:=Microsoft.Office.Interop.Excel.XlTe xtQualifier.xlTextQualifierDoubleQuote,
ConsecutiveDelimiter:=True, Tab:=True, Semicolon:=False, _
Comma:=False, Space:=True, Other:=False,
FieldInfo:=Microsoft.Office.Interop.Excel.XlColumn DataType.xlGeneralFormat,
TextVisualLayout:=Microsoft.Office.Interop.Excel.X lTextVisualLayoutType.xlTextVisualLTR,
DecimalSeparator:=".", ThousandsSeparator:=",",
TrailingMinusNumbers:=True)

Sep 7 '06 #1
2 10327
Wow. I might have solved my problem accidentally. By taking out the
"oBook =" in front of everything (and just using oExcel as my object),
the text file opened just fine, even without all the mumbo-jumbo after
the filename. My code's this now...

Dim oExcel As New Microsoft.Office.Interop.Excel.Application

oExcel = CreateObject("Excel.Application")
oExcel.Visible = True
oExcel.Workbooks.Open("C:\TextTest.txt")

I assume then that I must just not be dimensioning something correctly.
I wonder why the program knows it's a space delimited file, since as
you can see I haven't stated that anywhere in my code. Thoughts?
Ja**********@ec.gc.ca wrote:
Hi everyone,
I'm having trouble opening space delimited textfiles in Excel from
Visual Basic.net. I'm able to control, open and modify Excel files
from Visual Basic, so my Excel reference seems to be working ok. I
just don't know what I'm doing when I try to open a space delimited
file and want to put the data into columns. I tried recording a macro
in VBA and going from there, but then I got stuff saying "Name
'xlDelimited' is not declared", etc. So then I started throwing
'Microsoft.Office.Interop.Excel.XLTextParsingType. xlDelimited' in front
because I saw that online somewhere, and things looked like they might
work, but alas, they did not. So here I am. If you haven't figured it
out yet, I'm not a programmer and I'm pretty new to VB, so I would
really appreciate some help on this. I've pasted the not-so-pretty
code I've attempted below solely for your amusement. To be honest, I'm
not even sure what about 90% of it means. With this code I get an
error saying something like "Expression does not produce a value".
Thanks for any help offered.

Dim oExcel As New Microsoft.Office.Interop.Excel.Application
Dim oBook As Object
Dim oSheet As Object

oExcel = CreateObject("Excel.Application")
oExcel.Visible = True
oBook = oExcel.Workbooks.OpenText("C:\TextTest.txt",
Origin:=437, StartRow:=1,
DataType:=Microsoft.Office.Interop.Excel.XlTextPar singType.xlDelimited,
TextQualifier:=Microsoft.Office.Interop.Excel.XlTe xtQualifier.xlTextQualifierDoubleQuote,
ConsecutiveDelimiter:=True, Tab:=True, Semicolon:=False, _
Comma:=False, Space:=True, Other:=False,
FieldInfo:=Microsoft.Office.Interop.Excel.XlColumn DataType.xlGeneralFormat,
TextVisualLayout:=Microsoft.Office.Interop.Excel.X lTextVisualLayoutType.xlTextVisualLTR,
DecimalSeparator:=".", ThousandsSeparator:=",",
TrailingMinusNumbers:=True)
Sep 7 '06 #2
Hi Jacob,

Would you like to try OrchidGrid, which can parse/import delimited text
files and transfer/export the data to Excel?

Check this,
http://www.springsys.com/netproducts/orchid.asp


Hi everyone,
I'm having trouble opening space delimited textfiles in Excel from
Visual Basic.net. I'm able to control, open and modify Excel files
from Visual Basic, so my Excel reference seems to be working ok. I
just don't know what I'm doing when I try to open a space delimited
file and want to put the data into columns. I tried recording a macro
in VBA and going from there, but then I got stuff saying "Name
'xlDelimited' is not declared", etc. So then I started throwing
'Microsoft.Office.Interop.Excel.XLTextParsingType. xlDelimited' in front
because I saw that online somewhere, and things looked like they might
work, but alas, they did not. So here I am. If you haven't figured it
out yet, I'm not a programmer and I'm pretty new to VB, so I would
really appreciate some help on this. I've pasted the not-so-pretty
code I've attempted below solely for your amusement. To be honest, I'm
not even sure what about 90% of it means. With this code I get an
error saying something like "Expression does not produce a value".
Thanks for any help offered.

Dim oExcel As New Microsoft.Office.Interop.Excel.Application
Dim oBook As Object
Dim oSheet As Object

oExcel = CreateObject("Excel.Application")
oExcel.Visible = True
oBook = oExcel.Workbooks.OpenText("C:\TextTest.txt",
Origin:=437, StartRow:=1,
DataType:=Microsoft.Office.Interop.Excel.XlTextPar singType.xlDelimited,
TextQualifier:=Microsoft.Office.Interop.Excel.XlTe xtQualifier.xlTextQualifierDoubleQuote,
ConsecutiveDelimiter:=True, Tab:=True, Semicolon:=False, _
Comma:=False, Space:=True, Other:=False,
FieldInfo:=Microsoft.Office.Interop.Excel.XlColumn DataType.xlGeneralFormat,
TextVisualLayout:=Microsoft.Office.Interop.Excel.X lTextVisualLayoutType.xlTextVisualLTR,
DecimalSeparator:=".", ThousandsSeparator:=",",
TrailingMinusNumbers:=True)

Sep 7 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Carl Mercier | last post by:
Hi! I have written a little class in .NET to convert a DataTable or a dataView to a comma-delimited text file. This file eventually gets imported in Excel or Word. Everything works great, I...
1
by: mr_ocp | last post by:
Hi friends I need routines to create an excel file with worksheets for each customer and a text file as well for each customer, first worksheet would be a "Summary Report", here is the code that...
9
by: Bernie Yaeger | last post by:
Is there a way to convert or copy a .xml file to a comma delimited text file using vb .net? Thanks for any help. Bernie Yaeger
16
by: iwdu15 | last post by:
how can i open a file i saved and place the info into different text boxes?
3
by: Avi | last post by:
I need to create a text file that has the data from the 10 tables in the database. The number of fields in the tables exceeds 255 and so I cannot make a new table with all the fields and then...
6
by: =?Utf-8?B?UmljaA==?= | last post by:
'--this code works but only reads text into one column when contains multiple cols Dim ds1x As New DataSet Dim ConStr As String = _ "Provider=Microsoft.Jet.OLEDB.4.0;Data...
4
by: Ted Theo | last post by:
hello cdma enthusiasts. long time no speak. i have an .adp which is connected to a sql 2k back end from which i need to export a table to a tab delimited text file. the export text wizard...
16
by: Phil Stanton | last post by:
I have a form with a button which is supposed to open an Excel file (With lots of Macros /VBA) in it. The Excel file gets it's data from the Access program Here is the code Private Sub...
1
by: asedt | last post by:
With my Excel macro and two text files I want to create a new textfile containing the first textfile then text from the sheet and then the second textfile. My problem is that i don't know how to...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.