- Katılım
- 11 Mart 2005
- Mesajlar
- 3,062
- Excel Vers. ve Dili
- Office 2013 İngilizce
Çok teşekkürler Haluk HocamAşağıdaki kod ise, ekli "TestFile.text" dosyasında 15 sütunda yer alan verilerin arasında son sütunu "2" olanları alıp, "Data.xlsx" dosyasında "Rapor" sayfasına yazar.
Download files - Filemail
Click here to view and download these shared files from Filemail.comwww.filemail.com
C#:Sub Test2() 'Haluk - 04/01/2023 ' Dim adoCAT As Object, adoTable As Object, myFile As String Dim objConn As Object Dim ColumnCount As Integer, i As Integer myFile = ThisWorkbook.Path & "\Data.xlsx" If Dir(myFile, vbDirectory) <> "" Then Kill myFile Set objConn = CreateObject("ADODB.Connection") strArgs = "Driver={Microsoft Excel Driver (*.xls, *.xlsx, *.xlsm, *.xlsb)}; Readonly=False; DBQ=" & ThisWorkbook.FullName objConn.Open strArgs strSQL = " Select * From " & _ "[Text;CharacterSet=65001;Database=" & ThisWorkbook.Path & ";HDR=No].[TestFile.txt]" Set RS = objConn.Execute(strSQL) ColumnCount = RS.Fields.Count Set adoCAT = CreateObject("ADOX.Catalog") adoCAT.ActiveConnection = "Provider=Microsoft.ACE.OLEDB.12.0" & _ ";Data Source=" & myFile & _ ";Extended Properties=Excel 12.0 Xml" Set adoTable = CreateObject("ADOX.Table") adoTable.Name = "Rapor" For i = 1 To ColumnCount Set adoColumn = CreateObject("ADOX.Column") adoColumn.Name = "F" & i adoTable.Columns.Append adoColumn Next adoCAT.Tables.Append adoTable strSQL = " Insert Into [" & myFile & "].[Rapor$] Select * From " & _ "[Text;CharacterSet=65001;Database=" & ThisWorkbook.Path & ";HDR=No].[TestFile.txt] Where F15= 2" objConn.Execute (strSQL) Set objConn = Nothing Set adoTable = Nothing Set adoCAT = Nothing End Sub
.
Son düzenleme: