Hello,
i am using this code to import a csv file to an existing excel file. This works fine, but now i want to do something different. i have 2 excel sheets with information i want to import. After clicking on the button a windows explorer window should be opened, there i can select the file i need. In the first Column, of the excel sheet with the values i want to import, there are articels which can be ordered, in the second there is a order number and in the fifth there is the price. I dont need the other information, so i have thought to import only column A, B and E. The code here should do it, but there is an error i haven't found it yet. The price of the articles are in the form 23,3. After importing the comma should be replaced by a point (23.3). But its a date for excel, so i dont know how i can do this. Mark the column as a text doesn't help here.
Sub test()
Dim fn As String, cn As Object, rs As Object
fn = Application.GetOpenFilename("xlsxFiles,*.xlsx")
If fn = "False" Then Exit Sub
Set cn = CreateObject("ADODB.Connection")
Set rs = CreateObject("ADODB.Recordset")
With cn
.Provider = "Microsoft.Jet.OLEDB.4.0"
.Properties("Extended Properties") = "Text;HDR=YES;FMT=Delimited;"
.Open Left$(fn, InStrRev(fn, "\"))
End With
rs.Open "Select F1, F2, F5 from `" & Mid$(fn, InStrRev(fn, "\") + 1) & "`", cn, 3, 3
Range("a" & Rows.Count).End(xlUp)(3).Value = fn
Range("a" & Rows.Count).End(xlUp)(2).CopyFromRecordset rs
Set rs = Nothing: Set cn = Nothing
End Sub
I would be thankful for any help.
regards
Jedd21
Bookmarks