Merhaba,
Aşağıdaki kodlar ile veri alıyorum ama kopyalanan verilerin sadece sayı olanları geliyor. Aralıktaki metinler gelmiyor nedendir acaba?
Const SourceFile As String = "C:\Temp\Test.xls" ' kapalı dosyanın yeri
Const SourceSheet As String = "Fiş" ' kapalı dosyanın içindeki sayfanın adı
Const SourceRange As String = "a1:m25000" ' veri alınacak aralık
Private Sub GetDataFromClosedWorkbook(SourceFile As String, SourceRange As String)
Dim dbConnection As Object, rs As Object
Dim dbConnectionString As String
Set dbConnection = CreateObject("ADODB.Connection")
Set rst = CreateObject("ADODB.recordset")
Dim TargetCell As Range
dbConnectionString = "DRIVER={Microsoft Excel Driver (*.xls)};" & _
"ReadOnly=1;DBQ=" & SourceFile
On Error GoTo InvalidInput
dbConnection.Open dbConnectionString
Set rs = dbConnection.Execute("[" & SourceSheet & "$" & SourceRange & "]")
Sheets(1).Range("A1").CopyFromRecordset rs 'alınan verinin kopyalanacağı yer
rs.Close
dbConnection.Close
Set TargetCell = Nothing
Set rs = Nothing
Set dbConnection = Nothing
On Error GoTo 0
Exit Sub
InvalidInput:
MsgBox "The source file or source range is invalid!", vbExclamation
End Sub
Sub getir()
Call GetDataFromClosedWorkbook(SourceFile, SourceRange)
End Sub
Aşağıdaki kodlar ile veri alıyorum ama kopyalanan verilerin sadece sayı olanları geliyor. Aralıktaki metinler gelmiyor nedendir acaba?
Const SourceFile As String = "C:\Temp\Test.xls" ' kapalı dosyanın yeri
Const SourceSheet As String = "Fiş" ' kapalı dosyanın içindeki sayfanın adı
Const SourceRange As String = "a1:m25000" ' veri alınacak aralık
Private Sub GetDataFromClosedWorkbook(SourceFile As String, SourceRange As String)
Dim dbConnection As Object, rs As Object
Dim dbConnectionString As String
Set dbConnection = CreateObject("ADODB.Connection")
Set rst = CreateObject("ADODB.recordset")
Dim TargetCell As Range
dbConnectionString = "DRIVER={Microsoft Excel Driver (*.xls)};" & _
"ReadOnly=1;DBQ=" & SourceFile
On Error GoTo InvalidInput
dbConnection.Open dbConnectionString
Set rs = dbConnection.Execute("[" & SourceSheet & "$" & SourceRange & "]")
Sheets(1).Range("A1").CopyFromRecordset rs 'alınan verinin kopyalanacağı yer
rs.Close
dbConnection.Close
Set TargetCell = Nothing
Set rs = Nothing
Set dbConnection = Nothing
On Error GoTo 0
Exit Sub
InvalidInput:
MsgBox "The source file or source range is invalid!", vbExclamation
End Sub
Sub getir()
Call GetDataFromClosedWorkbook(SourceFile, SourceRange)
End Sub
