- Katılım
- 15 Nisan 2007
- Mesajlar
- 3,472
- Excel Vers. ve Dili
- Office 2010 & 2013 tr
DOSYA İndirmek/Yüklemek için ÜCRETLİ ALTIN ÜYELİK Gereklidir!
Altın Üyelik Hakkında Bilgi
Aktaramazsınız.ADO-SQL kullanmanız lazım.Merhaba,
Ekli dosyada ExecuteExcel4Macro yöntemi ile kapalı dosyadan veri alabiliyorum. Aynı yöntemi tersten uygulamak mümkün mü? ExecuteExcel4Macro yöntemi ile kapalı dosyaya veri aktarabilir miyiz?
Sub veri_yaz()
Dim conn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim i As Byte
Set conn = New ADODB.Connection
Set rs = New ADODB.Recordset
conn.Open "Provider=Microsoft.Jet.Oledb.4.0;Data Source=" & ThisWorkbook.Path & _
"\Veri.xls;extended properties=""Excel 8.0;hdr=yes"""
rs.Open "Select * from [Sayfa1$]", conn, 1, 3
baslik = InputBox("Başlık Giriniz", "BAŞLIK", "Başlık" & rs.RecordCount + 1)
Do While Not rs.EOF
rs(0).Value = baslik
rs(1).Value = Format(Date, "dd.mm.yyyy")
rs(2).Value = Cells(2, "A").Value
rs(3).Value = Cells(3, "A").Value
rs(4).Value = Cells(4, "A").Value
rs(5).Value = Cells(5, "A").Value
rs(6).Value = Cells(6, "A").Value
rs(7).Value = Cells(7, "A").Value
rs(8).Value = Cells(8, "A").Value
rs(9).Value = Cells(9, "A").Value
rs(10).Value = Cells(10, "A").Value
rs(11).Value = Cells(11, "A").Value
rs(12).Value = Cells(12, "A").Value
rs(13).Value = Cells(13, "A").Value
rs(14).Value = Cells(14, "A").Value
rs(15).Value = Cells(15, "A").Value
rs.Update
MsgBox "Kayıt Başarı ile girildi."
End Sub
Sub ado_ile_veri_al()
Dim conn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim sat As Long
Range("B2:B65536").ClearContents
Set conn = New ADODB.Connection
Set rs = New ADODB.Recordset
conn.Open "Provider=Microsoft.Jet.Oledb.4.0;Data Source=" & ThisWorkbook.Path & _
"\Veri.xls;extended properties=""Excel 8.0;hdr=yes"""
rs.Open "Select * from [Sayfa1$]", conn, 1, 3
sat = Cells(65536, "B").End(xlUp).Row + 1
rs.MoveFirst
Do While Not rs.EOF
Cells(sat, "B").Value = rs(0).Value
sat = sat + 1
Cells(sat, "B").Value = rs(1).Value
sat = sat + 1
Cells(sat, "B").Value = rs(2).Value
sat = sat + 1
Cells(sat, "B").Value = rs(3).Value
sat = sat + 1
Cells(sat, "B").Value = rs(4).Value
sat = sat + 1
Cells(sat, "B").Value = rs(5).Value
sat = sat + 1
Cells(sat, "B").Value = rs(6).Value
sat = sat + 1
Cells(sat, "B").Value = rs(7).Value
sat = sat + 1
Cells(sat, "B").Value = rs(8).Value
sat = sat + 1
Cells(sat, "B").Value = rs(9).Value
sat = sat + 1
Cells(sat, "B").Value = rs(10).Value
sat = sat + 1
Cells(sat, "B").Value = rs(11).Value
sat = sat + 1
Cells(sat, "B").Value = rs(12).Value
sat = sat + 1
Cells(sat, "B").Value = rs(13).Value
sat = sat + 1
Cells(sat, "B").Value = rs(14).Value
sat = sat + 1
Cells(sat, "B").Value = rs(15).Value
sat = sat + 1
rs.MoveNext
Loop
MsgBox "Veriler Başarı ile alındı."
End Sub
Sub excel4_makro_ile_veri_al()
Dim sat As Long, i As Long, sat2 As Long
sat = 2
sat2 = Application.ExecuteExcel4Macro("COUNTA('" & ThisWorkbook.Path & "\[Veri.xls]Sayfa1'!C1)")
Range("B2:B65536").ClearContents
For j = 2 To sat2
For i = 1 To 16
Cells(sat, "B").Value = Application.ExecuteExcel4Macro("'" & ThisWorkbook.Path & "\[Veri.xls]Sayfa1'!R" & j & "C" & i)
sat = sat + 1
Next
Next
MsgBox "Veriler alındı"
End Sub
Sub veri_yaz()
Dim conn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim i As Byte
Set conn = New ADODB.Connection
Set rs = New ADODB.Recordset
conn.Open "Provider=Microsoft.Jet.Oledb.4.0;Data Source=" & ThisWorkbook.Path & _
"\Veri.xls;extended properties=""Excel 8.0;hdr=yes"""
rs.Open "Select * from [Sayfa1$]", conn, 1, 3
baslik = InputBox("Başlık Giriniz", "BAŞLIK", "Başlık" & rs.RecordCount + 1)
If Not rs.EOF Then
rs.AddNew
rs(0).Value = baslik
rs(1).Value = Format(Date, "dd.mm.yyyy")
rs(2).Value = Cells(2, "A").Value
rs(3).Value = Cells(3, "A").Value
rs(4).Value = Cells(4, "A").Value
rs(5).Value = Cells(5, "A").Value
rs(6).Value = Cells(6, "A").Value
rs(7).Value = Cells(7, "A").Value
rs(8).Value = Cells(8, "A").Value
rs(9).Value = Cells(9, "A").Value
rs(10).Value = Cells(10, "A").Value
rs(11).Value = Cells(11, "A").Value
rs(12).Value = Cells(12, "A").Value
rs(13).Value = Cells(13, "A").Value
rs(14).Value = Cells(14, "A").Value
rs(15).Value = Cells(15, "A").Value
rs.Update
rs.Close
End If
MsgBox "Kayıt Başarı ile girildi."
End Sub
Peki bilgi için teşekkürler. Anladığım kadarıyla Ado ile yapacağımız işlemler sınırlı. Sadece veri depolamak için kullanacağız. Bul-Değiştir-Sil gibi işlemleri yapamayacağız.Selamlar,
Mustafa bey,
Ado ile istediğiniz satıra veri kaydı yapamıyorsunuz. Database mantığı ile çalıştığı için ilk satır başlık olarak değerlendiriliyor ve ondan sonraki satırlarda veri kaydı için kullanılıyor.
Benden bir hatırlatma.
Veri tabanı için excel uygun değildir.Bunun yerine mdb uzantılı dosyaları(Accsess dosyaları) veya sql server dosyalarını kullanınız.O zaman rahatlıkla bul sil değiştir yapabilrsiniz.Uygun sql sorgusunu kurarak tabi ki.![]()
Korhan Bey,
Teşekkür ederim. Verdiğiniz linki inceledim. Gerçekten bu konuda akla gelebilecek tüm soruların cevabı var. Bu dosyadan istifade etmeyi düşünüyorum. Şu an kodların mantığını anlamaya çalışıyorum.
Evren Bey,
Öneriniz mantıklı, kesinlikle haklı olduğunuzu düşünüyorum; ancak mdb uzantılı bir dosyayı henüz hiç açmadım bile. Excelde sorunlarımı rahatlıkla çözebiliyorum, işin içine mdb girerse sürekli yardım almam gerekecek. Bu nedenle ona şu an için hiç cesaret edemiyorum.
Soru: Excel4Makro'da CountA oluyor; Countif olmuyor mu? Tüm aramalarıma rağmen countif'i bulamadım. Ya da kaydedilmiş bir verinin aynısını kaydetmemek için bir çözüm var mı?
Teşekkürler...Countif 'e bende hiç rastlamadım.
Bu sorununuzu hücrelerde döngüye girerek oygun sorguyu kurarak aşabilirsiniz.
Sub veri_yaz()
Dim conn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim i As Byte
Set conn = New ADODB.Connection
Set rs = New ADODB.Recordset
conn.Open "Provider=Microsoft.Jet.Oledb.4.0;Data Source=" & ThisWorkbook.Path & _
"\Veri.xls;extended properties=""Excel 8.0;hdr=yes"""
rs.Open "Select * from [Sayfa1$]", conn, 1, 3
baslik = InputBox("Başlık Giriniz", "BAŞLIK", "Başlık" & rs.RecordCount + 1)
rs.AddNew
rs(0).Value = baslik
rs(1).Value = Format(Date, "dd.mm.yyyy")
rs(2).Value = Cells(2, "A").Value
rs(3).Value = Cells(3, "A").Value
rs(4).Value = Cells(4, "A").Value
rs(5).Value = Cells(5, "A").Value
rs(6).Value = Cells(6, "A").Value
rs(7).Value = Cells(7, "A").Value
rs(8).Value = Cells(8, "A").Value
rs(9).Value = Cells(9, "A").Value
rs(10).Value = Cells(10, "A").Value
rs(11).Value = Cells(11, "A").Value
rs(12).Value = Cells(12, "A").Value
rs(13).Value = Cells(13, "A").Value
rs(14).Value = Cells(14, "A").Value
rs(15).Value = Cells(15, "A").Value
rs.Update
rs.Close
MsgBox "Kayıt Başarı ile girildi."
End Sub
Sub veri_yaz()
Dim conn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim i As Byte
Set conn = New ADODB.Connection
Set rs = New ADODB.Recordset
conn.Open "Provider=Microsoft.Jet.Oledb.4.0;Data Source=" & ThisWorkbook.path & _
"\Veri.xls;extended properties=""Excel 8.0;hdr=yes"""
rs.Open "Select * from [Sayfa1$]", conn, 1, 3
Baslik = InputBox("Başlık Giriniz", "BAŞLIK", "Başlık" & rs.RecordCount + 1)
rs.AddNew
rs(0).Value = Baslik
rs(1).Value = Format(Date, "dd.mm.yyyy")
For j = 2 To WorksheetFunction.CountA(Worksheets(ActiveSheet.Name).Range("A2:A500")) + 2
rs(j).Value = Cells(j, "A").Value
Next j
rs.Update
rs.Close
MsgBox "Kayıt Başarı ile girildi."
End Sub