PC Review


Reply
Thread Tools Rate Thread

Best way to import .csv

 
 
=?Utf-8?B?Y290dGFnZTY=?=
Guest
Posts: n/a
 
      13th Sep 2007
I need to import a .csv file to a specific destination in an existing
spreadsheet. I have code that works that I've used before, but I end up with
incrementing named ranges such as bake_1, bake_2, etc. that I then need to
delete. I also have some code that will search for those names and delete
them, but I wondered if there was a better way to do the import. The code
I'm using to import is just recorded from the Data - Get External data
commands. I'm developing this in Excel 2000 to be used on PCs using Excel
2003. I've included the import code below. Thanks for your help!
With ActiveSheet.QueryTables.Add(Connection:= _
"TEXT;C:\Lotus\work\123\BAKE.csv", Destination:=Range("AC1"))
.Name = "BAKE"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.TextFilePromptOnRefresh = False
.TextFilePlatform = xlWindows
.TextFileStartRow = 1
.TextFileParseType = xlDelimited
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = False
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = True
.TextFileSpaceDelimiter = False
.TextFileColumnDataTypes = Array(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1)
.Refresh BackgroundQuery:=False
End With
End Sub

 
Reply With Quote
 
 
 
 
=?Utf-8?B?VG9tIE9naWx2eQ==?=
Guest
Posts: n/a
 
      13th Sep 2007
for each nm in Activesheet.parent.Names
if instr(1,nm.name,"bake",vbTextcompare) then
nm.Delete
end if
Next
With ActiveSheet.QueryTables.Add(Connection:= _
"TEXT;C:\Lotus\work\123\BAKE.csv", Destination:=Range("AC1"))
.Name = "BAKE"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.TextFilePromptOnRefresh = False
.TextFilePlatform = xlWindows
.TextFileStartRow = 1
.TextFileParseType = xlDelimited
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = False
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = True
.TextFileSpaceDelimiter = False
.TextFileColumnDataTypes = Array(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1)
.Refresh BackgroundQuery:=False
End With
End Sub

--
Regards,
Tom Ogilvy


"cottage6" wrote:

> I need to import a .csv file to a specific destination in an existing
> spreadsheet. I have code that works that I've used before, but I end up with
> incrementing named ranges such as bake_1, bake_2, etc. that I then need to
> delete. I also have some code that will search for those names and delete
> them, but I wondered if there was a better way to do the import. The code
> I'm using to import is just recorded from the Data - Get External data
> commands. I'm developing this in Excel 2000 to be used on PCs using Excel
> 2003. I've included the import code below. Thanks for your help!
> With ActiveSheet.QueryTables.Add(Connection:= _
> "TEXT;C:\Lotus\work\123\BAKE.csv", Destination:=Range("AC1"))
> .Name = "BAKE"
> .FieldNames = True
> .RowNumbers = False
> .FillAdjacentFormulas = False
> .PreserveFormatting = True
> .RefreshOnFileOpen = False
> .RefreshStyle = xlInsertDeleteCells
> .SavePassword = False
> .SaveData = True
> .AdjustColumnWidth = True
> .RefreshPeriod = 0
> .TextFilePromptOnRefresh = False
> .TextFilePlatform = xlWindows
> .TextFileStartRow = 1
> .TextFileParseType = xlDelimited
> .TextFileTextQualifier = xlTextQualifierDoubleQuote
> .TextFileConsecutiveDelimiter = False
> .TextFileTabDelimiter = False
> .TextFileSemicolonDelimiter = False
> .TextFileCommaDelimiter = True
> .TextFileSpaceDelimiter = False
> .TextFileColumnDataTypes = Array(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
> 1)
> .Refresh BackgroundQuery:=False
> End With
> End Sub
>

 
Reply With Quote
 
=?Utf-8?B?Y290dGFnZTY=?=
Guest
Posts: n/a
 
      13th Sep 2007
Thanks very much Tom. Your code to delete the names is much shorter than
mine, and works great. Have a good day!

"Tom Ogilvy" wrote:

> for each nm in Activesheet.parent.Names
> if instr(1,nm.name,"bake",vbTextcompare) then
> nm.Delete
> end if
> Next
> With ActiveSheet.QueryTables.Add(Connection:= _
> "TEXT;C:\Lotus\work\123\BAKE.csv", Destination:=Range("AC1"))
> .Name = "BAKE"
> .FieldNames = True
> .RowNumbers = False
> .FillAdjacentFormulas = False
> .PreserveFormatting = True
> .RefreshOnFileOpen = False
> .RefreshStyle = xlInsertDeleteCells
> .SavePassword = False
> .SaveData = True
> .AdjustColumnWidth = True
> .RefreshPeriod = 0
> .TextFilePromptOnRefresh = False
> .TextFilePlatform = xlWindows
> .TextFileStartRow = 1
> .TextFileParseType = xlDelimited
> .TextFileTextQualifier = xlTextQualifierDoubleQuote
> .TextFileConsecutiveDelimiter = False
> .TextFileTabDelimiter = False
> .TextFileSemicolonDelimiter = False
> .TextFileCommaDelimiter = True
> .TextFileSpaceDelimiter = False
> .TextFileColumnDataTypes = Array(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
> 1)
> .Refresh BackgroundQuery:=False
> End With
> End Sub
>
> --
> Regards,
> Tom Ogilvy
>
>
> "cottage6" wrote:
>
> > I need to import a .csv file to a specific destination in an existing
> > spreadsheet. I have code that works that I've used before, but I end up with
> > incrementing named ranges such as bake_1, bake_2, etc. that I then need to
> > delete. I also have some code that will search for those names and delete
> > them, but I wondered if there was a better way to do the import. The code
> > I'm using to import is just recorded from the Data - Get External data
> > commands. I'm developing this in Excel 2000 to be used on PCs using Excel
> > 2003. I've included the import code below. Thanks for your help!
> > With ActiveSheet.QueryTables.Add(Connection:= _
> > "TEXT;C:\Lotus\work\123\BAKE.csv", Destination:=Range("AC1"))
> > .Name = "BAKE"
> > .FieldNames = True
> > .RowNumbers = False
> > .FillAdjacentFormulas = False
> > .PreserveFormatting = True
> > .RefreshOnFileOpen = False
> > .RefreshStyle = xlInsertDeleteCells
> > .SavePassword = False
> > .SaveData = True
> > .AdjustColumnWidth = True
> > .RefreshPeriod = 0
> > .TextFilePromptOnRefresh = False
> > .TextFilePlatform = xlWindows
> > .TextFileStartRow = 1
> > .TextFileParseType = xlDelimited
> > .TextFileTextQualifier = xlTextQualifierDoubleQuote
> > .TextFileConsecutiveDelimiter = False
> > .TextFileTabDelimiter = False
> > .TextFileSemicolonDelimiter = False
> > .TextFileCommaDelimiter = True
> > .TextFileSpaceDelimiter = False
> > .TextFileColumnDataTypes = Array(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
> > 1)
> > .Refresh BackgroundQuery:=False
> > End With
> > End Sub
> >

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
access import wizard doesn't import all rows of excel file Linda in Iowa Microsoft Access External Data 1 24th Aug 2008 04:48 AM
Import Wizard dropping fields defined by Import Spec Access 2007 DinosRose Microsoft Access External Data 4 11th Dec 2007 05:06 PM
Import user-defined fields from Outlook to Access Dynamic import ? =?Utf-8?B?Q2h1Y2tmMjAx?= Microsoft Access External Data 3 21st Nov 2004 07:30 AM
when import text file, there has not advanced botton in import window new Microsoft Access 0 14th Apr 2004 04:13 PM
Import option grayed out in Windows Address Book, cannot Import LDIF Mark Windows XP General 2 22nd Nov 2003 02:47 PM


Features
 

Advertising
 

Newsgroups
 


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