473,395 Members | 1,454 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,395 software developers and data experts.

CSV file import into Excel sheet

9
Hello,
I am trying to import 4 separate csv files from 4 different servers into an excel sheet.I want to write a macro which will automate this.Also, i want to append the name of the server for each file in next free column.
How do i ensure that the next csv file does not overwrite the previous import.i.e to make sure that next free cell (*,1) is selected before the next import.Here is what i have been able to generate so far:
Expand|Select|Wrap|Line Numbers
  1. With ActiveSheet.QueryTables.Add(Connection:= _
  2.         "TEXT;C:\Documents and Settings\Forcados\My Documents\My Data Sources\Output.NET\ssh\ssh1_list.csv" _
  3.         , Destination:=Range("A1"))
  4.         .Name = "LAG-BSC_list"
  5.         .FieldNames = True
  6.         .RowNumbers = False
  7.         .FillAdjacentFormulas = False
  8.         .PreserveFormatting = True
  9.         .RefreshOnFileOpen = False
  10.         .RefreshStyle = xlInsertDeleteCells
  11.         .SavePassword = False
  12.         .SaveData = True
  13.         .AdjustColumnWidth = True
  14.         .RefreshPeriod = 0
  15.         .TextFilePromptOnRefresh = False
  16.         .TextFilePlatform = 437
  17.         .TextFileStartRow = 1
  18.         .TextFileParseType = xlDelimited
  19.         .TextFileTextQualifier = xlTextQualifierDoubleQuote
  20.         .TextFileConsecutiveDelimiter = False
  21.         .TextFileTabDelimiter = True
  22.         .TextFileSemicolonDelimiter = True
  23.         .TextFileCommaDelimiter = False
  24.         .TextFileSpaceDelimiter = False
  25.         .TextFileColumnDataTypes = Array(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, _
  26.         1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)
  27.         .TextFileTrailingMinusNumbers = True
  28.         .Refresh BackgroundQuery:=False
  29.     End With
  30.     ActiveWindow.SmallScroll Down:=15
  31.     Range("A41").Select
  32.     With ActiveSheet.QueryTables.Add(Connection:= _
  33.         "TEXT;C:\Documents and Settings\Forcados\My Documents\My Data Sources\Output.NET\ssh\ssh1_list.csv" _
  34.         , Destination:=Range("A41"))
  35.         .Name = "IBD-BSC_list"
  36.         .FieldNames = True
  37.         .RowNumbers = False
  38.         .FillAdjacentFormulas = False
  39.         .PreserveFormatting = True
  40.         .RefreshOnFileOpen = False
  41.         .RefreshStyle = xlInsertDeleteCells
  42.         .SavePassword = False
  43.         .SaveData = True
  44.         .AdjustColumnWidth = True
  45.         .RefreshPeriod = 0
  46.         .TextFilePromptOnRefresh = False
  47.         .TextFilePlatform = 437
  48.         .TextFileStartRow = 1
  49.         .TextFileParseType = xlDelimited
  50.         .TextFileTextQualifier = xlTextQualifierDoubleQuote
  51.         .TextFileConsecutiveDelimiter = False
  52.         .TextFileTabDelimiter = True
  53.         .TextFileSemicolonDelimiter = True
  54.         .TextFileCommaDelimiter = False
  55.         .TextFileSpaceDelimiter = False
  56.         .TextFileColumnDataTypes = Array(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, _
  57.         1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)
  58.         .TextFileTrailingMinusNumbers = True
  59.         .Refresh BackgroundQuery:=False
  60.     End With
Jan 18 '07 #1
3 3905
Killer42
8,435 Expert 8TB
So, is it the "A41" in your example that you want to replace with something dynamically generated?
Jan 19 '07 #2
DONE1
9
It is not always A41.
The next free cell depends on the content of the csv file.The problem is how to identify the next free cell in the first column(i.e cell(*,1). & to indicate the source of the file in a column in the excell file.

Thanks
Jan 19 '07 #3
Killer42
8,435 Expert 8TB
It is not always A41.
The next free cell depends on the content of the csv file.The problem is how to identify the next free cell in the first column(i.e cell(*,1). & to indicate the source of the file in a column in the excell file.
Hm... well, identifying the next empty cell should be fairly simple. Although I'm sure there is a more direct way, one thing you could try is to do the equivalent of jumping to the bottom of column A, then hitting [End]-[Up] to jump to the next non-blank, then move down a row.

Not sure about the server-name thing, though.

Don't forget, you can often find the way to do something in code by just doing it yourself, while Excel records it as a macro. Then go edit/copy the code that it generated. This doesn't always work, but it's a handy shortcut.
Jan 19 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Paul | last post by:
I was wondering if anyone has had an issue where using vba code to read an excel file and import the data into an access table some records are not imported from the excel file. It seems looking at...
8
by: Nick M | last post by:
Hello All, Excellent info here Thanks! I am very new to using access in general and I am on a learning curve. I'm trying to import an excel workbook (with worksheets) into an access db via a...
2
by: Sreedhar Vankayala | last post by:
Hi, I joined a project where we need to import data from a excel file into sql server via the asp.net. After doing a long research found that #1. Upload Excel file to the server #2. Load or...
1
by: Peter Stojkovic | last post by:
I am importing data from an EXCEL XLS-File via OLEDB-Provider The command is SELECT * from Everything works fine if the first sheet is named sheet1 But sometimes the name is not known...
12
by: kath | last post by:
How do I read an Excel file in Python? I have found a package to read excel file, which can be used on any platform. http://www.lexicon.net/sjmachin/xlrd.htm I installed and working on the...
8
by: FireGeek | last post by:
I have a database that is split appropriately. Annually, we need to add data from .xls files. I have added code so with a click of a button, it will import this data as a new table into the...
0
by: Anish G | last post by:
Hi All, I am getting the below given error while running my application in live server. In my local machine, its working fine. Please help me as it is very urgent for me. Exception from...
2
by: pulavarthipraveen | last post by:
Overview: We have a requirement in the c#.NET 1.0 windows application. There will be some input text file in the user’s machine. The user should browse and select the input text file and also select...
2
by: vikassawant | last post by:
hi, It's very crazy problem.I want to import excel sheet data in to JTable but I can't find any solution. Actually what I want,suppose there are 7 rows and 5 columns in a table.If I...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.