exportar datagrid a excel
Publicado por pako montaño (15 intervenciones) el 29/10/2006 02:02:27
hola como estas, me podiran ayudar en lo siguiente:
necesito esportar un datagrid a excel tengo el siguiente codigo:
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
pero me marca en liguiente error:
ERROR DE COMPILACION
NO SE DEFINE EL TIPO DE FINIDO POR EL USUARIO
la linea de codigo donde me lo marca es la siguiente:
Dim excelApp As Excel.Application
en un foro tiene el mismo codigo yb dice que encontro la libreria pero no se a que se refiere, de ante mano muchas gracias
necesito esportar un datagrid a excel tengo el siguiente codigo:
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
pero me marca en liguiente error:
ERROR DE COMPILACION
NO SE DEFINE EL TIPO DE FINIDO POR EL USUARIO
la linea de codigo donde me lo marca es la siguiente:
Dim excelApp As Excel.Application
en un foro tiene el mismo codigo yb dice que encontro la libreria pero no se a que se refiere, de ante mano muchas gracias
Valora esta pregunta


0