Ayuda con el objeto Excel
Publicado por amarti93 (16 intervenciones) el 17/01/2005 18:38:17
Tengo el siguiente codigo :
Partimos del hecho que no sabemos si el fichero donde vamos a exportar los datos existe o no, alguién me puede decir como puedo controlar si existe el fichero o no mediante metodos o propiedades del objeto excel o mediante alguna API de windows.
Muchas Gracias
-----------------------------------------------
Private Function Exportar(Data() As Variant, Fichero As String) As Boolean
Dim xlApp As Excel.Application
Dim wkb As Excel.Workbook
Dim wkbSheet As Excel.Worksheet
Dim Rng As Excel.Range
Dim fila As Integer
Dim columna As Integer
On Error GoTo tError
Exportar = False
Set xlApp = New Excel.Application
Set wkb = xlApp.Workbooks.Add
Set wkbSheet = wkb.Worksheets(1)
Set Rng = wkbSheet.Range("A1:" + Chr(vaPlantilla.MaxCols + 64) + CStr(vaPlantilla.DataRowCnt + 1))
For fila = 0 To UBound(Data, 1)
For columna = 0 To vaPlantilla.MaxCols - 1
wkbSheet.Range(Chr(columna + 1 + 64) + CStr(fila + 1)) = CStr(Data(fila, columna))
Next
Next
For columna = 1 To vaPlantilla.MaxCols
wkbSheet.Range(Chr(columna + 64) + CStr(1)).Interior.color = &H99EEEE
Next
'No sabemos si el fichero existe o no
wkb.SaveAs Fichero
wkb.Close True
xlApp.Quit
Exportar = True
Set wkb = Nothing
Set wkbSheet = Nothing
Set xlApp = Nothing
Set Rng = Nothing
.......
Partimos del hecho que no sabemos si el fichero donde vamos a exportar los datos existe o no, alguién me puede decir como puedo controlar si existe el fichero o no mediante metodos o propiedades del objeto excel o mediante alguna API de windows.
Muchas Gracias
-----------------------------------------------
Private Function Exportar(Data() As Variant, Fichero As String) As Boolean
Dim xlApp As Excel.Application
Dim wkb As Excel.Workbook
Dim wkbSheet As Excel.Worksheet
Dim Rng As Excel.Range
Dim fila As Integer
Dim columna As Integer
On Error GoTo tError
Exportar = False
Set xlApp = New Excel.Application
Set wkb = xlApp.Workbooks.Add
Set wkbSheet = wkb.Worksheets(1)
Set Rng = wkbSheet.Range("A1:" + Chr(vaPlantilla.MaxCols + 64) + CStr(vaPlantilla.DataRowCnt + 1))
For fila = 0 To UBound(Data, 1)
For columna = 0 To vaPlantilla.MaxCols - 1
wkbSheet.Range(Chr(columna + 1 + 64) + CStr(fila + 1)) = CStr(Data(fila, columna))
Next
Next
For columna = 1 To vaPlantilla.MaxCols
wkbSheet.Range(Chr(columna + 64) + CStr(1)).Interior.color = &H99EEEE
Next
'No sabemos si el fichero existe o no
wkb.SaveAs Fichero
wkb.Close True
xlApp.Quit
Exportar = True
Set wkb = Nothing
Set wkbSheet = Nothing
Set xlApp = Nothing
Set Rng = Nothing
.......
Valora esta pregunta


0