Buenos días Abraham,
Tengo una platilla de excel para facturas, con macros. Me gustaría modificar los primeros números de las facturas, es decir ahora me pone el número F000 y querría poner F20060000 y luego que el contador fuera numerando las facturas, 1, 2, 3... He tratado de modificalo pero no funciona. Abajo te pongo todas las macros de esta hoja:
Option Explicit
Const strRuta As String = "C:\Facturas\Formacion\" 'Ruta donde se guardarán las facturas (poner la que se desee).
Dim strNombreLibro As String
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Static blnRecursiva As Boolean
If blnRecursiva Then Exit Sub
If Me. Path <> "" Then Exit Sub
Dim intRespuesta As Integer
intRespuesta = MsgBox(prompt:=" ¿Desea salir sin guardar esta factura? " & vbNewLine & vbNewLine & "<Sí> para cerrar el libro sin guardarlo. " & vbNewLine & "<No> para guardar la factura como " & strNombreLibro & ". Xls y cerrar el libro. " & vbNewLine & "<Cancelar> para volver al libro sin guardarlo. ", Buttons:=vbYesNoCancel + vbQuestion)
If intRespuesta = vbYes Then
Cancel = True
blnRecursiva = True
Me. Close savechanges:=False
ElseIf intRespuesta = vbNo Then
Application. EnableEvents = False
Me. SaveAs Filename:=strNombreLibro, FileFormat:=xlWorkbookNormal
Application. EnableEvents = True
ElseIf intRespuesta = vbCancel Then
Cancel = True
End If
End Sub
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
If Me. Path <> "" Then Exit Sub
Application. EnableEvents = False
Me. SaveAs Filename:=strNombreLibro, FileFormat:=xlWorkbookNormal
Application. EnableEvents = True
Cancel = True
ActiveWindow. Caption = strNombreLibro
End Sub
Private Sub Workbook_Open()
If Me. FileFormat = xlTemplate Or Me. Path <> "" Then Exit Sub
Dim fsB As FileSearch
Dim intNuevoNúmero As Integer
Set fsB = Application. FileSearch
With fsB
. NewSearch
. LookIn = strRuta
. SearchSubFolders = False
. Filename = "FactF*. Xls"
If. Execute(SortBy:=msoSortByFileName, sortorder:=msoSortOrderDescending) = 0 Then intNuevoNúmero = 1 Else intNuevoNúmero = Val(Mid(. FoundFiles(1), Len(. LookIn) + 7, 4)) + 1
End With
Me. Worksheets("FACTURAS Y PRESUPUESTOS"). Range("C19") = "F" & Right("000" & intNuevoNúmero, 4) 'El número de factura se pondría en A1
strNombreLibro = strRuta & "FactF" & Right("000" & intNuevoNúmero, 4)
ActiveWindow. Caption = strNombreLibro & " - Sin guardar"
Set fsB = Nothing
End Sub
Espero que puedas ayudarme, la plantilla no la he hecho yo, me la paso un amigo, que no sabe como solucionar este problema.
Mil gracias y felices fiestas
Amaia Echarri