Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 38
Default macro to import file (help with a piece of code)

I actually use a macro to import a txt file with a lot of columns

Below there is a part of the code that allows me to import the file...
I want to import only the first 6 columns (from A to g) and actually I
import all the columns and then erase the exceeding with

Columns("G:IV").Select
Selection.Delete Shift:=xlToLeft

How can I import them without doing the delete procedure...?
I think there is sthg to do with

.TextFileColumnDataTypes = Array(1, 1, 1, 1, 1, 1, 1)

But I don't understand what....



With ActiveSheet.QueryTables.Add(Connection:=fileToOpen _
, Destination:=Range("A1"))
.Name = "Push"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.TextFilePromptOnRefresh = False
.TextFilePlatform = 850
.TextFileStartRow = 3
.TextFileParseType = xlDelimited
.TextFileTextQualifier = xlTextQualifierNone
.TextFileConsecutiveDelimiter = True
.TextFileTabDelimiter = True
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = False
.TextFileSpaceDelimiter = True
.TextFileColumnDataTypes = Array(1, 1, 1, 1, 1, 1, 1)
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False
Columns("G:IV").Select
Selection.Delete Shift:=xlToLeft


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default macro to import file (help with a piece of code)

first initialize an array to pass to TextFileColumnDataTypes:

dim v(0 to 255) as Long
for i = 0 to 255
if i <= 7
v(i) = 1
else
v(i) = 9
end if
Next

9 means to skip the column

then change you code:

.TextFileColumnDataTypes = v

--
Regards,
Tom Ogilvy

"uriel78" wrote in message
...
I actually use a macro to import a txt file with a lot of columns

Below there is a part of the code that allows me to import the file...
I want to import only the first 6 columns (from A to g) and actually I
import all the columns and then erase the exceeding with

Columns("G:IV").Select
Selection.Delete Shift:=xlToLeft

How can I import them without doing the delete procedure...?
I think there is sthg to do with

.TextFileColumnDataTypes = Array(1, 1, 1, 1, 1, 1, 1)

But I don't understand what....



With ActiveSheet.QueryTables.Add(Connection:=fileToOpen _
, Destination:=Range("A1"))
.Name = "Push"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.TextFilePromptOnRefresh = False
.TextFilePlatform = 850
.TextFileStartRow = 3
.TextFileParseType = xlDelimited
.TextFileTextQualifier = xlTextQualifierNone
.TextFileConsecutiveDelimiter = True
.TextFileTabDelimiter = True
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = False
.TextFileSpaceDelimiter = True
.TextFileColumnDataTypes = Array(1, 1, 1, 1, 1, 1, 1)
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False
Columns("G:IV").Select
Selection.Delete Shift:=xlToLeft




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 38
Default macro to import file (help with a piece of code)

Thank you very much, it does exactly what i was looking for!!


"Tom Ogilvy" ha scritto nel messaggio
...
first initialize an array to pass to TextFileColumnDataTypes:

dim v(0 to 255) as Long
for i = 0 to 255
if i <= 7
v(i) = 1
else
v(i) = 9
end if
Next

9 means to skip the column

then change you code:

.TextFileColumnDataTypes = v

--
Regards,
Tom Ogilvy



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 38
Default macro to import file (help with a piece of code)

:-(
it seems to work 'til yesterday....

now it doesn't...

I just want to import only those 7 columns and I want values already on the
sheet to be replaced by the data imported without moving any rows or
columns...how can I do...I'm struggling...:-(



"Tom Ogilvy" ha scritto nel messaggio
...
first initialize an array to pass to TextFileColumnDataTypes:

dim v(0 to 255) as Long
for i = 0 to 255
if i <= 7
v(i) = 1
else
v(i) = 9
end if
Next

9 means to skip the column

then change you code:

.TextFileColumnDataTypes = v

--
Regards,
Tom Ogilvy

"uriel78" wrote in message
...
I actually use a macro to import a txt file with a lot of columns

Below there is a part of the code that allows me to import the file...
I want to import only the first 6 columns (from A to g) and actually I
import all the columns and then erase the exceeding with

Columns("G:IV").Select
Selection.Delete Shift:=xlToLeft

How can I import them without doing the delete procedure...?
I think there is sthg to do with

.TextFileColumnDataTypes = Array(1, 1, 1, 1, 1, 1, 1)

But I don't understand what....



With ActiveSheet.QueryTables.Add(Connection:=fileToOpen _
, Destination:=Range("A1"))
.Name = "Push"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.TextFilePromptOnRefresh = False
.TextFilePlatform = 850
.TextFileStartRow = 3
.TextFileParseType = xlDelimited
.TextFileTextQualifier = xlTextQualifierNone
.TextFileConsecutiveDelimiter = True
.TextFileTabDelimiter = True
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = False
.TextFileSpaceDelimiter = True
.TextFileColumnDataTypes = Array(1, 1, 1, 1, 1, 1, 1)
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False
Columns("G:IV").Select
Selection.Delete Shift:=xlToLeft






  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 38
Default macro to import file (help with a piece of code)

:-) evrything gets ok this morning, maybe last night my brain was too
hot....:-)



"uriel78" ha scritto nel messaggio
...
:-(
it seems to work 'til yesterday....

now it doesn't...

I just want to import only those 7 columns and I want values already on

the
sheet to be replaced by the data imported without moving any rows or
columns...how can I do...I'm struggling...:-(



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
Interpretation of a piece of code FARAZ QURESHI Excel Discussion (Misc queries) 3 December 30th 07 11:29 PM
What is wrong with this vba piece of code? Jo[_2_] Excel Discussion (Misc queries) 4 October 4th 07 05:01 PM
VB Code or Excel macro to run Query/Import on Access file Harry[_8_] Excel Programming 13 February 22nd 05 07:27 PM
changing a piece of code Ajit Excel Programming 0 September 17th 04 02:45 PM
Query on small piece of code Mike[_65_] Excel Programming 7 March 4th 04 03:23 PM


All times are GMT +1. The time now is 03:03 AM.

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"