Problemas con exportacion a Excel
Hola, mira un ya puedo exportar un archivo a excel, el problemas es que hay que exportar el archivo con el mismo nombre sin que se pierda el anterior archivo, entonces la idea es al anterior renombrarle con la fecha anterior, y ese es mi problema por favor ayudame
Te envio un ejemplo donde exporto colocandole yo el nombre al archivo:
Dim xl As Excel.Application
Dim xlvb As Excel.Workbook
Dim NameDb As String
Dim cnn As ADODB.Connection
Dim FileName As String
Dim sExcelfileName As String
CommonDialog1.DialogTitle = "Guardar Como"
CommonDialog1.DefaultExt = "XLS"
CommonDialog1.Filter = "Excel (*.xls)|*.xls"
CommonDialog1.Action = 2
FileName = CommonDialog1.FileName
If FileName = "" Then Exit Sub
sExcelfileName = FileName
If VerificarFichero(sExcelfileName) Then
Set xl = CreateObject("Excel.Application")
Set xlvb = xl.Workbooks.Open(sExcelfileName)
xl.Visible = True
Else
MsgBox ("El Archivo " & FileName & " no existe ")
Exit Sub
End If
'funcion para ver la existencia de un archivo
Public Function VerificarFichero(sNombreFichero As String) As Boolean
On Error Resume Next
VerificarFichero = True
Open sNombreFichero For Input As #1
If Err Then
VerificarFichero = False
'MsgBox ("El Archivo " & sNombreFichero & " no existe.")
Exit Function
End If
Close #1
End Function
Aunque un poco tarde espero te sirva
Dim xl As Excel.Application
Dim xlvb As Excel.Workbook
Dim NameDb As String
Dim cnn As ADODB.Connection
Dim FileName As String
Dim sExcelfileName As String
CommonDialog1.DialogTitle = "Guardar Como"
CommonDialog1.DefaultExt = "XLS"
CommonDialog1.Filter = "Excel (*.xls)|*.xls"
CommonDialog1.Action = 2
FileName = CommonDialog1.FileName
If FileName = "" Then Exit Sub
sExcelfileName = FileName
If VerificarFichero(sExcelfileName) Then
Set xl = CreateObject("Excel.Application")
Set xlvb = xl.Workbooks.Open(sExcelfileName)
xl.Visible = True
Else
MsgBox ("El Archivo " & FileName & " no existe ")
Exit Sub
End If
'funcion para ver la existencia de un archivo
Public Function VerificarFichero(sNombreFichero As String) As Boolean
On Error Resume Next
VerificarFichero = True
Open sNombreFichero For Input As #1
If Err Then
VerificarFichero = False
'MsgBox ("El Archivo " & sNombreFichero & " no existe.")
Exit Function
End If
Close #1
End Function
Aunque un poco tarde espero te sirva
