Copy Paste Without Opening The .csv file/s

epoiezam

New Member
Joined
Jan 28, 2016
Messages
15
Hi Guys,,

Need your help.. How to make this formula works with .csv file/s.
Thank you :)

Dim fso As Object
Dim fld As Object
Dim strSearch As String
Dim strPath As String
Dim strFile As String
Dim wOut As Worksheet
Dim wbk As Workbook
Dim wks As Worksheet
Dim lRow As Long
Dim rFound As Range
Dim strFirstAddress As String


On Error GoTo ErrHandler
Application.ScreenUpdating = False
Application.Visible = False

'Change as desired
strPath = UserForm1.Label44.Caption
strSearch = UserForm1.TextBox1.Value


'Set wOut = Worksheets.Add
lRow = 3
With Sheet2
' .Cells(lRow, 3) = "Workbook"
' .Cells(lRow, 4) = "Worksheet"
' .Cells(lRow, 5) = "Cell"
'.Cells(lRow, 6) = "Text in Cell"

Set fso = CreateObject("Scripting.FileSystemObject")
Set fld = fso.GetFolder(strPath)


'strFile = Dir(strPath & "\*.xls*")
strFile = Dir(strPath & "\*.xlsx")
Do While strFile <> ""
Set wbk = Workbooks.Open _
(Filename:=strPath & "" & strFile, _
UpdateLinks:=0, _
ReadOnly:=True, _
AddToMRU:=False)

Application.Visible = False

For Each wks In wbk.Worksheets
Set rFound = wks.UsedRange.Find(strSearch) ' find all in sheet


If Not rFound Is Nothing Then
strFirstAddress = rFound.Address
End If
Do
If rFound Is Nothing Then
Exit Do
Else
lRow = lRow + 1
'.Cells(lRow, 3) = wbk.Name
'.Cells(lRow, 4) = wks.Name
'.Cells(lRow, 5) = rFound.Address
.Cells(lRow, 6).EntireRow.Value = rFound.EntireRow.Value
End If
Set rFound = wks.Range("K:K").FindNext(After:=rFound) ' column = Range("K:K"), all = Cells
Loop While strFirstAddress <> rFound.Address
Next


wbk.Close (True)
strFile = Dir

Loop
Application.Visible = False
.Columns("A:D").EntireColumn.AutoFit
End With
'MsgBox "Done"



ExitHandler:
Set wOut = Nothing
Set wks = Nothing
Set wbk = Nothing
Set fld = Nothing
Set fso = Nothing
Application.ScreenUpdating = True
Exit Sub


ErrHandler:
MsgBox Err.Description, vbExclamation
Resume ExitHandler
 

Some videos you may like

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying

Watch MrExcel Video

Forum statistics

Threads
1,109,013
Messages
5,526,266
Members
409,689
Latest member
martin_br

This Week's Hot Topics

Top