Mefisto...diabeł czy anioł?
Witam
Przy pomocy ADO ,kopiuje pewny obszar z 1 skoroszytu do drugiego skoroszytu.
Dziwna rzecz siê dzieje ,poniewa¿ nie kopiuj± siê niektóre wiersze :(
Czy kto¶ ju¿ spotka³ sie z czym¶ podobnym ?
FUNKCJA :
Sub GetWorksheetData(strSourceFile As String, strSQL As String, TargetCell As Range)
Dim cn As ADODB.Connection, rs As ADODB.Recordset, f As Integer, r As Long
If TargetCell Is Nothing Then Exit Sub
Set cn = New ADODB.Connection
On Error Resume Next
cn.Open "DRIVER={Microsoft Excel Driver (*.xls)};DriverId=790;" & _
"ReadOnly=True;DBQ=" & strSourceFile & ";"
On Error GoTo 0
If cn Is Nothing Then
MsgBox "Can't find the file!", vbExclamation, ThisWorkbook.Name
Exit Sub
End If
Set rs = New ADODB.Recordset
On Error Resume Next
rs.Open strSQL, cn, adOpenForwardOnly, adLockReadOnly, adCmdText
On Error GoTo 0
If rs Is Nothing Then
MsgBox "Can't open the file!", vbExclamation, ThisWorkbook.Name
cn.Close
Set cn = Nothing
Exit Sub
End If
TargetCell.CopyFromRecordset rs
If rs.State = adStateOpen Then
rs.Close
End If
Set rs = Nothing
cn.Close
Set cn = Nothing
End Sub
ODWO£ANIE DO NIEJ :
Dim x as string
x = "SELECT * FROM [Kraj$A5:BW43];"
GetWorksheetData "\\\Dane_2007\Plany wysy³ek\Wys_K_09.xls", x, ThisWorkbook.Worksheets("planwys").Cells(1, 1)
pzdr
mrjoy
[ Dodano: 2007-09-25, 09:43 ]
zanotowane.pl doc.pisz.pl pdf.pisz.pl katkaras.opx.pl
Przy pomocy ADO ,kopiuje pewny obszar z 1 skoroszytu do drugiego skoroszytu.
Dziwna rzecz siê dzieje ,poniewa¿ nie kopiuj± siê niektóre wiersze :(
Czy kto¶ ju¿ spotka³ sie z czym¶ podobnym ?
FUNKCJA :
Sub GetWorksheetData(strSourceFile As String, strSQL As String, TargetCell As Range)
Dim cn As ADODB.Connection, rs As ADODB.Recordset, f As Integer, r As Long
If TargetCell Is Nothing Then Exit Sub
Set cn = New ADODB.Connection
On Error Resume Next
cn.Open "DRIVER={Microsoft Excel Driver (*.xls)};DriverId=790;" & _
"ReadOnly=True;DBQ=" & strSourceFile & ";"
On Error GoTo 0
If cn Is Nothing Then
MsgBox "Can't find the file!", vbExclamation, ThisWorkbook.Name
Exit Sub
End If
Set rs = New ADODB.Recordset
On Error Resume Next
rs.Open strSQL, cn, adOpenForwardOnly, adLockReadOnly, adCmdText
On Error GoTo 0
If rs Is Nothing Then
MsgBox "Can't open the file!", vbExclamation, ThisWorkbook.Name
cn.Close
Set cn = Nothing
Exit Sub
End If
TargetCell.CopyFromRecordset rs
If rs.State = adStateOpen Then
rs.Close
End If
Set rs = Nothing
cn.Close
Set cn = Nothing
End Sub
ODWO£ANIE DO NIEJ :
Dim x as string
x = "SELECT * FROM [Kraj$A5:BW43];"
GetWorksheetData "\\\Dane_2007\Plany wysy³ek\Wys_K_09.xls", x, ThisWorkbook.Worksheets("planwys").Cells(1, 1)
pzdr
mrjoy
[ Dodano: 2007-09-25, 09:43 ]