Visual Basic - XQ se keda el excel??

Life is soft - evento anual de software empresarial
 
Vista:

XQ se keda el excel??

Publicado por Altapy (7 intervenciones) el 18/05/2005 13:21:31
hola amigos tengo este codigo para pasar un datagrid auna hoja de excel, cuando lo abor la primera vez muy bien pero si kiero abrirlo de nuev sin cerrar la aplicacion se keda pilladoy no se porq si me podeis ayudar, ahi va mi caodigo

Private Sub Command1_Click()
Dim wkbNew As Excel.Workbook
Dim wkbSheet As Excel.Worksheet
Dim Rng As Excel.Range
If Dir("C:\Archivo.xls") <> "" Then 'Si Existe el Archivo
Kill "C:\Archivo.xls" 'Lo Eliminamos
End If
Set wkbNew = Workbooks.Add
wkbNew.SaveAs "C:\Archivo.xls"
Set wkbSheet = wkbNew.Worksheets(1)
wkbSheet.Cells(1, 1) = "Serial"
wkbSheet.Cells(1, 2) = "Usuario"
wkbSheet.Cells(1, 3) = "Lugar"
wkbSheet.Cells(1, 4) = "Departamento"
wkbSheet.Cells(1, 5) = "Tipo Ordenador"
wkbSheet.Cells(1, 6) = "Procesador"
wkbSheet.Cells(1, 7) = "Placa"
wkbSheet.Cells(1, 8) = "Chip"
wkbSheet.Cells(1, 9) = "Ram"
wkbSheet.Cells(1, 10) = "Slots libres"
wkbSheet.Cells(1, 11) = "Memoria"
wkbSheet.Cells(1, 12) = "Tarjeta Grafica"
wkbSheet.Cells(1, 13) = "Conector"
wkbSheet.Cells(1, 14) = "Tarjeta Red"
wkbSheet.Cells(1, 15) = "Velocidad"
wkbSheet.Cells(1, 16) = "SO"
wkbSheet.Cells(1, 17) = "IP"
wkbSheet.Cells(1, 18) = "Fecha Compra"
wkbSheet.Cells(1, 19) = "Monitor"
wkbSheet.Cells(1, 20) = "Modelo"
wkbSheet.Cells(1, 21) = "Pulgadas"
Set Rng = wkbSheet.Range("A2:" + Chr(dbgListado.Columns.Count + 64) + CStr(adoBusqueda.Recordset.RecordCount))
dbgListado.Row = 0 'se coloca el cursor en la primera fila
dbgListado.Refresh
For i = 0 To adoBusqueda.Recordset.RecordCount - 1
For j = 0 To dbgListado.Columns.Count - 1
dbgListado.Col = j
dbgListado.Row = i
Rng.Range(Chr(j + 1 + 64) + CStr(i + 1)) = dbgListado.Text
Next j
adoBusqueda.Recordset.MoveNext
Next i
'Close and save the file
wkbNew.Close True
'Si queremos Abrir el Archivo
Dim MyValue
MyValue = Shell("rundll32.exe url.dll,FileProtocolHandler " & "C:\Archivo.xls", vbMaximizedFocus)
Set wkbNew = Nothing
Set wkbSheet = Nothing
Set Rng = Nothing
End Sub
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:XQ se keda el excel??

Publicado por Jack Randall (1 intervención) el 30/05/2005 23:48:28
antes del wkbNew.Close ponle

wkbNew.Visible = True
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:XQ se keda el excel??

Publicado por Marco (20 intervenciones) el 31/05/2005 16:52:27
mira esté codigo me funciona super bien, lo unico malo que las fechas me las da vuelta cuando el día es menor al mes pero funciona bien, si arreglo lo de las fechas te aviso.

Private Sub cmdtoexcell_Click()
Dim ApExcel As Variant
Set ApExcel = CreateObject("Excel.application")
' Hace que Excel se vea
ApExcel.Visible = True
'Agrega un nuevo Libro
ApExcel.Workbooks.Add
Dim wkbSheet As Excel.Worksheet
Dim Rng As Excel.Range
ApExcel.Cells(1, 1) = "CODIGO"
ApExcel.Cells(1, 2) = "NOMBRE PRODUCTO"
ApExcel.Cells(1, 3) = "CANTIDAD"
ApExcel.Cells(1, 4) = "FECHA INGRESO"
ApExcel.Cells(1, 5) = "STOCK ACTUAL"
ApExcel.Cells(1, 6) = "PROVEEDOR"
' Hace una Seleccion de celdas y pone bordes de Color
ApExcel.Range("A1:F1").Borders.Color = RGB(255, 0, 0)

Set Rng = ApExcel.Range("A2:" + Chr(DataGrid1.Columns.Count + 64) + CStr(Adodc1.Recordset.RecordCount))

With Adodc1.Recordset
If .BOF = False Then .MoveFirst
If .EOF = False Then
Do Until .EOF
For I = 1 To .Fields.Count
If IsDate(.Fields(I - 1)) Then
Rng.Cells(.AbsolutePosition, I) = Format(.Fields(I - 1), "dd/mm/yyyy")
Else
Rng.Cells(.AbsolutePosition, I) = .Fields(I - 1)
End If
Next I
.MoveNext
Loop
End If
End With
Set ApExcel = Nothing
Set Rng = Nothing
End Sub
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