Visual Basic - ayuda con visual basic 6 y excel

Life is soft - evento anual de software empresarial
 
Vista:

ayuda con visual basic 6 y excel

Publicado por jexus27 (10 intervenciones) el 23/06/2010 18:56:53
hola amigos tengo un problema :estoy haciendo un sistema admnistrativo de una escuela y nesecito generar uns reportes pero los quiero en excel, y pss no se como hacer esto yo solo los habia hecho en data report ayudenme porfa... un ejemplito
ahhh y otro problem que tengo es de como hacer 2 cunsultas con la misma conexion es ala misma base es a 2 tablas que no estan relacionadas ,tambien para generar un reporte
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder

RE:ayuda con visual basic 6 y excel

Publicado por Julio (72 intervenciones) el 24/06/2010 00:11:22
Bueno para empezar entra en visual a referencias y tilda

microsoft excel 11.0 objet librery

luego en un modulo que llamaras moduloexcel pones

Public objExcel As Excel.Application

Public Function Inicio_Excel() As Boolean
'*
On Error GoTo Excel
'*
Set objExcel = New Excel.Application
objExcel.Visible = False
objExcel.SheetsInNewWorkbook = 1
objExcel.WindowState = xlMaximized
objExcel.Workbooks.Add
'*
Exit Function
'*
Excel:
Call ErrExcel
End Function

Public Sub ErrExcel()
'*
MsgBox Err.Description, vbInformation, "Información del Sistema"
'*
End Sub

Aqui algo de codigo para configurar la hoja excel.

'Conexion al objeto Excel:
Call Inicio_Excel
'*
With objExcel
'Título de la planilla:
.Caption = "Planilla de Excel:"
'Aliniación de los datos:
.Columns("A").HorizontalAlignment = xlHAlignCenter
.Columns("B").HorizontalAlignment = xlHAlignCenter
.Columns("C").HorizontalAlignment = xlHAlignCenter
.Columns("D").HorizontalAlignment = xlHAlignCenter
.Columns("E").HorizontalAlignment = xlHAlignCenter
.Columns("F").HorizontalAlignment = xlHAlignCenter
.Columns("G").HorizontalAlignment = xlHAlignCenter
.Columns("H").HorizontalAlignment = xlHAlignCenter
.Columns("I").HorizontalAlignment = xlHAlignCenter
'Ancho de columnas:
.Columns("A").ColumnWidth = 8
.Columns("B").ColumnWidth = 8
.Columns("C").ColumnWidth = 7.5
.Columns("D").ColumnWidth = 7.5
.Columns("E").ColumnWidth = 7.5
.Columns("F").ColumnWidth = 7.5
.Columns("G").ColumnWidth = 7.5
.Columns("H").ColumnWidth = 7.5
.Columns("I").ColumnWidth = 8
End With

LUEGO ALGO MAS DE CODIGILLO:
EL AQUI EN LA COMULNA 1 DE EXCEL PONDRA COD, EN LA 2 STOCK, ETC
ALGO PARA QUE VEAS TAMAÑO DE LETRA Y ANCHO DE LA FILA, BORDES, ETC

With objExcel
.Cells(Fila, 1) = "Cód." 'ENCABEZADOS
.Cells(Fila, 2) = "Stock"
.Cells(Fila, 3) = "Lun."
.Cells(Fila, 4) = "Mar."
.Cells(Fila, 5) = "Mie."
.Cells(Fila, 6) = "Jue."
.Cells(Fila, 7) = "Vie."
.Cells(Fila, 8) = "Sab."
.Cells(Fila, 9) = "Final"

.ActiveSheet.Cells(Fila, 1).Font.Size = 8 AQUI EL ANCHO DE LA COLUMNA
.ActiveSheet.Cells(Fila, 2).Font.Size = 8
.ActiveSheet.Cells(Fila, 3).Font.Size = 7.5
.ActiveSheet.Cells(Fila, 4).Font.Size = 7.5
.ActiveSheet.Cells(Fila, 5).Font.Size = 7.5
.ActiveSheet.Cells(Fila, 6).Font.Size = 7.5
.ActiveSheet.Cells(Fila, 7).Font.Size = 7.5
.ActiveSheet.Cells(Fila, 8).Font.Size = 7.5
.ActiveSheet.Cells(Fila, 9).Font.Size = 8

.ActiveSheet.Cells(Fila, 1).Font.Name = "Tahoma" 'TIPO DE LETRA
.ActiveSheet.Cells(Fila, 2).Font.Name = "Tahoma"
.ActiveSheet.Cells(Fila, 3).Font.Name = "Tahoma"
.ActiveSheet.Cells(Fila, 4).Font.Name = "Tahoma"
.ActiveSheet.Cells(Fila, 5).Font.Name = "Tahoma"
.ActiveSheet.Cells(Fila, 6).Font.Name = "Tahoma"
.ActiveSheet.Cells(Fila, 7).Font.Name = "Tahoma"
.ActiveSheet.Cells(Fila, 8).Font.Name = "Tahoma"
.ActiveSheet.Cells(Fila, 9).Font.Name = "Tahoma"

.ActiveSheet.Cells(Fila, 1).Font.Bold = True 'NEGRITA
.ActiveSheet.Cells(Fila, 2).Font.Bold = True
.ActiveSheet.Cells(Fila, 3).Font.Bold = True
.ActiveSheet.Cells(Fila, 4).Font.Bold = True
.ActiveSheet.Cells(Fila, 5).Font.Bold = True
.ActiveSheet.Cells(Fila, 6).Font.Bold = True
.ActiveSheet.Cells(Fila, 7).Font.Bold = True
.ActiveSheet.Cells(Fila, 8).Font.Bold = True
.ActiveSheet.Cells(Fila, 9).Font.Bold = True
.Range(.Cells(Fila, 1), .Cells(Fila, 9)).Borders.LineStyle = xlContinuous
End With

PARA TRANSEFERIR DATOS DE UNA BASE DE DATOS A UNA HOJA EXCEL:

Aqui tendria que ir tu select * con su tabla correspondiente:

una vez recuperados los registros de tu base de datos los empiezas a pasar a la hoja, dandole la hubicación, osea en la columna y fila correspondiente....etc

objExcel.ActiveSheet.Cells(Fila, Columna + 0) = .Fields!Key_Artículo
objExcel.ActiveSheet.Cells(Fila, Columna + 1) = .Fields!Stock
objExcel.ActiveSheet.Cells(Fila, Columna + 2) = .Fields!Articulo
objExcel.ActiveSheet.Cells(Fila, Columna + 3) =etc
objExcel.ActiveSheet.Cells(Fila, Columna + 4) = etc
objExcel.ActiveSheet.Cells(Fila, Columna + 5) = etc

Aca deveria id una variable llamada fila ej:

fila = fial + 1 , podria ser acompañada de un for...net de tu recorset.....en fin

saludos julio !!!!!!!!!!!!!!!!!!!
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

RE:ayuda con visual basic 6 y excel

Publicado por jexus27 (10 intervenciones) el 24/06/2010 01:02:35
orale carnal muchas graxias espero me pueda servir lo nesecito mucho
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar