Originally Posted by
olegvolf
Hello To All
I am sorry for intruding your thread I am new in this and do not know how to start a ne post.
Please see below a code that I am working on that I have a few problems:
Sub opebcsv()
Dim wbI As Workbook, wbO As Workbook
Dim wsI As Worksheet
Set wbI = ThisWorkbook
Set wsI = wbI.Sheets("Sheet1") '<~~ Sheet where you want to import
Set wbO = Workbooks.Open("C:\Users\volfs_000\Desktop\cradle-7200_4_5_new\Copy (10) of cradle7200_4_5_tom.csv")
wbO.Sheets(1).Cells.Copy wsI.Cells
wbO.Close SaveChanges:=False
Kill (wbO)
End Sub
I was wondering if I can change the open file line to -- the way that I will get a window to choose a folder and than the file that will be pulled is the latest one.
Second question is if I can set a creation range dates of the files wich are pulled
Thank you
Oleg
Like this?
Sub opebcsv()
Dim wbI As Workbook, wbO As Workbook
Dim wsI As Worksheet
Dim fd As FileDialog
Dim objfl As Variant
Set wbI = ThisWorkbook
Set wsI = wbI.Sheets("Sheet1") '<~~ Sheet where you want to import
Set fd = Application.FileDialog(msoFileDialogFilePicker)
With fd
.ButtonName = "Select"
.AllowMultiSelect = True
.Filters.Add "All Files", "*.*", 1
.Title = "Select file"
.InitialView = msoFileDialogViewDetails
.Show
For Each objfl In .SelectedItems
Set wbO = Workbooks.Open(objfl)
Next objfl
On Error GoTo 0
End With
Set fd = Nothing
wbO.Sheets(1).Cells.Copy wsI.Cells
wbO.Close SaveChanges:=False
Kill (wbO)
End Sub
Not sure what you mean with the second question.