Hello
seem this code doesn't work for me
in RESULT file should import data from TIRES file by selection folder based on matching with headers in ROW 23
but nothing occures anything so far
Sub test()
Dim myDir As String, cn As Object, rs As Object, r, myHeading
With Application.FileDialog(msoFileDialogFolderPicker)
.Title = "Select Folder"
If .Show Then myDir = .SelectedItems(1) & "\"
End With
If myDir = "" Then Exit Sub
Application.ScreenUpdating = False
Set cn = CreateObject("ADODB.Connection")
Set rs = CreateObject("ADODB.Recordset")
With Workbooks.Open(myDir & "RESULT.xlsm")
With .Sheets(1).Cells(1).CurrentRegion
myHeading = "`" & Join(.Parent.Evaluate(.Rows(1).Address & "&"""""), "`, `") & "`"
.Offset(1).ClearContents
End With
With cn
.Provider = "Microsoft.Ace.OLEDB.12.0"
.Properties("Extended Properties") = "Excel 12.0;HDR=Yes;"
.Open myDir & "TIRES.xlsx"
End With
rs.Open "Select " & myHeading & " From `Table1$`;", cn
.Sheets(1).[A1].CopyFromRecordset rs
'.Close True '<--- if you want to close Destination.xlsx, delete apostrophe.
End With
Set cn = Nothing: Set rs = Nothing
Application.ScreenUpdating = True
End Sub
thanks