Saltar al contenido
View in the app

A better way to browse. Learn more.

Ayuda Excel

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Eliminar archivo si existe uno en la unidad c:

publicado

que tal buen dia, bueno queria saber si me pueden ayudar con la siguiente macro, lo que quiero que haga es que a determinada fecha se cree un archivo con un nombre especifico a una ruta especifica y cuando se quiera acceder a ese archivo cheque primero si no existe el archivo creado y si existe se elimine el archivo que se esta utilizando y si llegaran a tener otro archivo como el borrado y cambien la fecha se elimine igual porque seguira el archivo guardado...AQUI LES DEJO LA MACRO QUE ESTOY MODIFICANDO TIENE UN ERROR ES QUE SI YA SE GUARDO UN ARCHIVO Y LE CAMBIO LA FECHA NO APARECE EL MENSAJE Y SE SUPONE QUE SE DEBE DE APARECER EL MENSAJE

Private Sub Workbook_Open()

Dim ruta As String
Dim archivo As String
ruta = ThisWorkbook.Path
archivo = "archibo.xls"
If Len(Dir(ruta & "\" & archivo)) = 0 Then
GoTo p1
Else: GoTo p2
GoTo p2
End

p1:
If Date >= DateSerial(2016, 2, 5) Then
Dim libro, carpeta, texto As String
libro = ("archivo")
carpeta = ("carpeta")
texto = "C:" & "carpeta" & "\" & libro & ".xls"
Set comprobarcarpeta = CreateObject("Scripting.FileSystemObject")
If Not comprobarcarpeta.folderExists(carpeta) Then
comprobarcarpeta.Createfolder (carpeta)
End If
Application.ScreenUpdating = False
ActiveSheet.Copy
Application.DisplayAlerts = False
Set wb = ActiveWorkbook
On Error Resume Next
With wb
.SaveAs texto
Application.DisplayAlerts = True
.Close True
End With
Set wb = Nothing
Sheets("Hoja1").Select
End If
End If

p2:
MsgBox "eliminado por que se encontro archivo"


End Sub[/CODE]

Featured Replies

publicado

OJO: tu código en su novena instrucción (después del "GoTo p2") tiene una línea que dice: End

esa instrucción termina la ejecución de cualquier código en proceso, derivado, pendiente, etc.

saludos,

hector.

publicado
  • Autor

[uSER=191685]@Héctor Miguel[/uSER]. Gracias por la observación pero aun asi engo un problema si le quito el end me salta al goto p2 y no hace el goto p1 primero

Archivado

Este tema está ahora archivado y está cerrado a más respuestas.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.