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
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
0