Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 108
Default Best way to import .csv

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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default Best way to import .csv

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

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 108
Default Best way to import .csv

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
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
import XML data...Is there a size limit on the import? MatthewG Excel Discussion (Misc queries) 0 February 10th 09 05:57 PM
How to Start Excel in Text Import Wizard for data import rlelvis Setting up and Configuration of Excel 0 July 10th 08 08:40 PM
PLEASE!! How can I un-grey the 'Data-Import External Data-Import Data' option ??? kirkm[_6_] Excel Programming 13 August 8th 06 10:01 AM
I can import Access Tables. But, I can't import Access queries nickg420[_8_] Excel Programming 0 August 5th 04 07:46 PM
Best Course to Import XML with DTD... Vagabond Software Excel Programming 0 July 30th 04 01:07 AM


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"