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: -
With ActiveSheet.QueryTables.Add(Connection:= _
-
"TEXT;C:\Documents and Settings\Forcados\My Documents\My Data Sources\Output.NET\ssh\ssh1_list.csv" _
-
, Destination:=Range("A1"))
-
.Name = "LAG-BSC_list"
-
.FieldNames = True
-
.RowNumbers = False
-
.FillAdjacentFormulas = False
-
.PreserveFormatting = True
-
.RefreshOnFileOpen = False
-
.RefreshStyle = xlInsertDeleteCells
-
.SavePassword = False
-
.SaveData = True
-
.AdjustColumnWidth = True
-
.RefreshPeriod = 0
-
.TextFilePromptOnRefresh = False
-
.TextFilePlatform = 437
-
.TextFileStartRow = 1
-
.TextFileParseType = xlDelimited
-
.TextFileTextQualifier = xlTextQualifierDoubleQuote
-
.TextFileConsecutiveDelimiter = False
-
.TextFileTabDelimiter = True
-
.TextFileSemicolonDelimiter = True
-
.TextFileCommaDelimiter = False
-
.TextFileSpaceDelimiter = False
-
.TextFileColumnDataTypes = Array(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, _
-
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)
-
.TextFileTrailingMinusNumbers = True
-
.Refresh BackgroundQuery:=False
-
End With
-
ActiveWindow.SmallScroll Down:=15
-
Range("A41").Select
-
With ActiveSheet.QueryTables.Add(Connection:= _
-
"TEXT;C:\Documents and Settings\Forcados\My Documents\My Data Sources\Output.NET\ssh\ssh1_list.csv" _
-
, Destination:=Range("A41"))
-
.Name = "IBD-BSC_list"
-
.FieldNames = True
-
.RowNumbers = False
-
.FillAdjacentFormulas = False
-
.PreserveFormatting = True
-
.RefreshOnFileOpen = False
-
.RefreshStyle = xlInsertDeleteCells
-
.SavePassword = False
-
.SaveData = True
-
.AdjustColumnWidth = True
-
.RefreshPeriod = 0
-
.TextFilePromptOnRefresh = False
-
.TextFilePlatform = 437
-
.TextFileStartRow = 1
-
.TextFileParseType = xlDelimited
-
.TextFileTextQualifier = xlTextQualifierDoubleQuote
-
.TextFileConsecutiveDelimiter = False
-
.TextFileTabDelimiter = True
-
.TextFileSemicolonDelimiter = True
-
.TextFileCommaDelimiter = False
-
.TextFileSpaceDelimiter = False
-
.TextFileColumnDataTypes = Array(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, _
-
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)
-
.TextFileTrailingMinusNumbers = True
-
.Refresh BackgroundQuery:=False
-
End With
3 3905
So, is it the "A41" in your example that you want to replace with something dynamically generated?
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
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.
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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...
|
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,...
|
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...
|
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,...
|
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...
| |