28/05/2012, 09:01
|
| | Fecha de Ingreso: mayo-2012 Ubicación: lima
Mensajes: 1
Antigüedad: 12 años, 6 meses Puntos: 0 | |
exportar datagrid a excel 2007 visual 6 Hola comunidad esta es mi duda:
quiero exportar el contenido de mi datagrid a excell, este datagrid va cambiado segun el filtro o comodin que yo ingrese, quiero exportar eso, pero me sale error
mi codigo es:
Private Sub Command3_Click()
Call Pase_Excel(Adodc1.RecordSource, Adodc1.ConnectionString)
End Sub
Public Sub Pase_Excel(Str_Sql As String, strConex As String)
Dim Int_Columnas As Integer
Dim Int_Filas As Integer
Dim rs_main As New ADODB.Recordset
Dim excelApp As Excel.Application
Dim excellibro As Excel.Workbook
Dim excelhoja As Excel.Worksheet
Dim Conn As ADODB.Connection
Set Conn = New ADODB.Connection
Conn.ConnectionString = strConex
Conn.Open
With rs_main
.CursorLocation = adUseClient
.CursorType = adOpenDynamic
.LockType = adLockBatchOptimistic
Set .ActiveConnection = Conn
.Open Str_Sql
End With
Set excelApp = New Excel.Application
Set excellibro = excelApp.Workbooks.Add
Set excelhoja = excellibro.ActiveSheet
Int_Columnas = rs_main.Fields.Count
For i = 1 To Int_Columnas
excelhoja.Cells(1, i) = rs_main.Fields(i - 1).Name
Next
If rs_main.RecordCount > 0 Then
rs_main.MoveFirst
For Int_Filas = 1 To rs_main.RecordCount
For j = 0 To Int_Columnas - 1
If IsNull(rs_main(j).Value) Then
excelhoja.Cells(Int_Filas + 2, j + 1) = ""
Else
excelhoja.Cells(Int_Filas + 2, j + 1) = CStr(rs_main(j).Value)
End If
Next
rs_main.MoveNext
Next
End If
excelApp.Visible = True
End Sub
y el error que me arroja es:
compile error
variable no definida
For i = 1 To Int_Columnas
me sombrea la "i"
no se si sera eso el error o falta declarar algo,
por siacaso ya agregue la referencia de microsoft excel 12.0 |