Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
Ed Ed is offline
external usenet poster
 
Posts: 399
Default Recorded macro opens, converts comma-del file and saves

I recorded a macro to open a text-type file (.rev extension) and then save
it as an xls workbook. It works well. But I have a question regarding the
conversion.

The macro recorded
Workbooks.OpenText Filename:=MyFile _
, Origin:=437, StartRow:=1, DataType:=xlDelimited, TextQualifier:= _
xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=False, Semicolon:=False
_
, Comma:=True, Space:=False, Other:=False, FieldInfo:=Array(Array(1, 1),
_

and follows with Array(x,1) up to 69,1. I understand this is one array for
each column. But as recorded, this on ly works correctly if I have 69 (or
less, I presume) columns, right? If one has more than 69 columns, am I
going to miss data? Is there a better way to code this to make sure I catch
every column?

Thanks.
Ed


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 415
Default Recorded macro opens, converts comma-del file and saves

Ed,
The FieldInfo argument is optional, so you can omit it.
That means that you cannot specify the data type of the fields, but will
have to let Excel guess.
Not sure if this would be suitable.

Otherwise you can build the array yourself before passing it, but again you
would need to the data type of each field.

NickHK

"Ed" bl...
I recorded a macro to open a text-type file (.rev extension) and then save
it as an xls workbook. It works well. But I have a question regarding the
conversion.

The macro recorded
Workbooks.OpenText Filename:=MyFile _
, Origin:=437, StartRow:=1, DataType:=xlDelimited, TextQualifier:= _
xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=False,
Semicolon:=False _
, Comma:=True, Space:=False, Other:=False, FieldInfo:=Array(Array(1,
1), _

and follows with Array(x,1) up to 69,1. I understand this is one array
for each column. But as recorded, this on ly works correctly if I have 69
(or less, I presume) columns, right? If one has more than 69 columns, am
I going to miss data? Is there a better way to code this to make sure I
catch every column?

Thanks.
Ed



  #3   Report Post  
Posted to microsoft.public.excel.programming
Ed Ed is offline
external usenet poster
 
Posts: 399
Default Recorded macro opens, converts comma-del file and saves

Thanks for the reply, Nick. If I omit the FieldInfo argument, then Excel
will automatically assign a data type to each column? So I will be assured
of getting each column, even if it varies between files?
Ed

"NickHK" wrote in message
...
Ed,
The FieldInfo argument is optional, so you can omit it.
That means that you cannot specify the data type of the fields, but will
have to let Excel guess.
Not sure if this would be suitable.

Otherwise you can build the array yourself before passing it, but again
you would need to the data type of each field.

NickHK

"Ed"
bl...
I recorded a macro to open a text-type file (.rev extension) and then save
it as an xls workbook. It works well. But I have a question regarding
the conversion.

The macro recorded
Workbooks.OpenText Filename:=MyFile _
, Origin:=437, StartRow:=1, DataType:=xlDelimited, TextQualifier:= _
xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=False,
Semicolon:=False _
, Comma:=True, Space:=False, Other:=False, FieldInfo:=Array(Array(1,
1), _

and follows with Array(x,1) up to 69,1. I understand this is one array
for each column. But as recorded, this on ly works correctly if I have
69 (or less, I presume) columns, right? If one has more than 69 columns,
am I going to miss data? Is there a better way to code this to make sure
I catch every column?

Thanks.
Ed





  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 415
Default Recorded macro opens, converts comma-del file and saves

Ed,
As I understand it.
Give it a test on various files with differing numbers of columns and see
what you get.

NickHK

"Ed" bl...
Thanks for the reply, Nick. If I omit the FieldInfo argument, then Excel
will automatically assign a data type to each column? So I will be
assured of getting each column, even if it varies between files?
Ed

"NickHK" wrote in message
...
Ed,
The FieldInfo argument is optional, so you can omit it.
That means that you cannot specify the data type of the fields, but will
have to let Excel guess.
Not sure if this would be suitable.

Otherwise you can build the array yourself before passing it, but again
you would need to the data type of each field.

NickHK

"Ed" bl...
I recorded a macro to open a text-type file (.rev extension) and then
save it as an xls workbook. It works well. But I have a question
regarding the conversion.

The macro recorded
Workbooks.OpenText Filename:=MyFile _
, Origin:=437, StartRow:=1, DataType:=xlDelimited, TextQualifier:= _
xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=False,
Semicolon:=False _
, Comma:=True, Space:=False, Other:=False, FieldInfo:=Array(Array(1,
1), _

and follows with Array(x,1) up to 69,1. I understand this is one array
for each column. But as recorded, this on ly works correctly if I have
69 (or less, I presume) columns, right? If one has more than 69
columns, am I going to miss data? Is there a better way to code this to
make sure I catch every column?

Thanks.
Ed







  #5   Report Post  
Posted to microsoft.public.excel.programming
Ed Ed is offline
external usenet poster
 
Posts: 399
Default Recorded macro opens, converts comma-del file and saves

Thanks for the boost, Nick.
Ed

"NickHK" wrote in message
...
Ed,
As I understand it.
Give it a test on various files with differing numbers of columns and see
what you get.

NickHK

"Ed"
bl...
Thanks for the reply, Nick. If I omit the FieldInfo argument, then Excel
will automatically assign a data type to each column? So I will be
assured of getting each column, even if it varies between files?
Ed

"NickHK" wrote in message
...
Ed,
The FieldInfo argument is optional, so you can omit it.
That means that you cannot specify the data type of the fields, but will
have to let Excel guess.
Not sure if this would be suitable.

Otherwise you can build the array yourself before passing it, but again
you would need to the data type of each field.

NickHK

"Ed"
bl...
I recorded a macro to open a text-type file (.rev extension) and then
save it as an xls workbook. It works well. But I have a question
regarding the conversion.

The macro recorded
Workbooks.OpenText Filename:=MyFile _
, Origin:=437, StartRow:=1, DataType:=xlDelimited, TextQualifier:= _
xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=False,
Semicolon:=False _
, Comma:=True, Space:=False, Other:=False, FieldInfo:=Array(Array(1,
1), _

and follows with Array(x,1) up to 69,1. I understand this is one array
for each column. But as recorded, this on ly works correctly if I have
69 (or less, I presume) columns, right? If one has more than 69
columns, am I going to miss data? Is there a better way to code this
to make sure I catch every column?

Thanks.
Ed











  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 415
Default Recorded macro opens, converts comma-del file and saves

Ed,
Test on some files, because the way Excel "guesse" which data type each
column contains can be surprising.
By default IIRC it reads the first 16 rows. So if the first 16 are numbers
and the rest are text, you may have problems.

NickHK

"Ed" .gbl...
Thanks for the boost, Nick.
Ed

"NickHK" wrote in message
...
Ed,
As I understand it.
Give it a test on various files with differing numbers of columns and see
what you get.

NickHK

"Ed" bl...
Thanks for the reply, Nick. If I omit the FieldInfo argument, then
Excel will automatically assign a data type to each column? So I will
be assured of getting each column, even if it varies between files?
Ed

"NickHK" wrote in message
...
Ed,
The FieldInfo argument is optional, so you can omit it.
That means that you cannot specify the data type of the fields, but
will have to let Excel guess.
Not sure if this would be suitable.

Otherwise you can build the array yourself before passing it, but again
you would need to the data type of each field.

NickHK

"Ed" bl...
I recorded a macro to open a text-type file (.rev extension) and then
save it as an xls workbook. It works well. But I have a question
regarding the conversion.

The macro recorded
Workbooks.OpenText Filename:=MyFile _
, Origin:=437, StartRow:=1, DataType:=xlDelimited, TextQualifier:=
_
xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=False,
Semicolon:=False _
, Comma:=True, Space:=False, Other:=False,
FieldInfo:=Array(Array(1, 1), _

and follows with Array(x,1) up to 69,1. I understand this is one
array for each column. But as recorded, this on ly works correctly if
I have 69 (or less, I presume) columns, right? If one has more than
69 columns, am I going to miss data? Is there a better way to code
this to make sure I catch every column?

Thanks.
Ed











  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Recorded macro opens, converts comma-del file and saves

I like to specify what I want--and not let excel guess:

Option Explicit
Sub testme01()
Dim fName As String
Dim myArray() As Variant
Dim iCtr As Long
Dim maxFields As Long

maxFields = Worksheets(1).Columns.Count

fName = "C:\sometextfile.txt"

ReDim myArray(1 To maxFields, 1 To 2)
For iCtr = 1 To maxFields
myArray(iCtr, 1) = iCtr
myArray(iCtr, 2) = 1
Next iCtr

Workbooks.OpenText Filename:=fName, Origin:=437, _
StartRow:=1, DataType:=xlDelimited, TextQualifier:=xlDoubleQuote, _
ConsecutiveDelimiter:=False, Tab:=False, Semicolon:=False, _
Comma:=True, Space:=False, Other:=False, _
FieldInfo:=myArray

End Sub

Ed wrote:

I recorded a macro to open a text-type file (.rev extension) and then save
it as an xls workbook. It works well. But I have a question regarding the
conversion.

The macro recorded
Workbooks.OpenText Filename:=MyFile _
, Origin:=437, StartRow:=1, DataType:=xlDelimited, TextQualifier:= _
xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=False, Semicolon:=False
_
, Comma:=True, Space:=False, Other:=False, FieldInfo:=Array(Array(1, 1),
_

and follows with Array(x,1) up to 69,1. I understand this is one array for
each column. But as recorded, this on ly works correctly if I have 69 (or
less, I presume) columns, right? If one has more than 69 columns, am I
going to miss data? Is there a better way to code this to make sure I catch
every column?

Thanks.
Ed


--

Dave Peterson
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro recorded... tabs & file names changed, macro hangs Steve Excel Worksheet Functions 3 October 30th 09 11:41 AM
Macro to Export Active Cells, Comma Sep to .txt file Stryves Excel Programming 2 July 11th 06 05:34 PM
button that opens open dialogs but saves path to sheet cereldine[_22_] Excel Programming 7 April 28th 06 12:08 PM
Excel saves CSV using semicolon(;) instead of comma(,) Daniel Amorim Excel Programming 1 September 21st 05 01:46 PM
how to get a macro to run when the file opens Mary[_6_] Excel Programming 3 September 29th 04 07:52 PM


All times are GMT +1. The time now is 11:42 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"