How to solve the problem with macro-enabled Excel files, are all files closed when saving or are they closed unexpectedly?

anderson bocanegra 0 Reputation points
2024-08-20T16:31:16.5933333+00:00

Hello, good day everyone, I have a problem with Microsoft Excel, regarding the macro-enabled files, it turns out that they close unexpectedly and when I try to save the macro-enabled files it closes only all the open excel files, with normal files it does not it happens. I also tried with several macro-enabled files on another computer and the same thing happened. I already tried the error repair tool and it didn't work. Can someone please help me?

Microsoft 365
Microsoft 365
Formerly Office 365, is a line of subscription services offered by Microsoft which adds to and includes the Microsoft Office product line.
5,071 questions
Excel
Excel
A family of Microsoft spreadsheet software with tools for analyzing, charting, and communicating data.
1,947 questions
Windows 11
Windows 11
A Microsoft operating system designed for productivity, creativity, and ease of use.
9,834 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Emi Zhang-MSFT 25,551 Reputation points Microsoft Vendor
    2024-08-21T05:58:38.1+00:00

    Hi,

    What version of Office did you use?

    I suggest you go to File- Account- and provide the information as shown in the following Picture:

    User's image

    Did this problem appear in all Excel files with code? Are the files that contain the issue all using specific code? Ever tried recording a simple copy-paste macro?

    Please be a bit more precise to explain your problem or you can upload a screenshot so that I can get more accurate solutions to this problem. I’m glad to help and follow up your reply.


    If the response is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

  2. anderson bocanegra 0 Reputation points
    2024-08-22T16:11:39.4833333+00:00

    User's image

    Hello good morning The image above shows the version of office you are currently using

    Indeed the problem appeared in all the files with code

    All the files have practically the same code, some have not been used lately and do not work either.

    never try to record simple copy and paste macros

    this is the code I use
    Sub Salvar()

    Dim NombreHoja As String

    Dim HojaDestino As Range

    Dim NuevaFila As Integer

    Dim FilasFactura As Integer

    Dim i As Integer

    Dim j As Integer

    Dim NumFactura As Integer

    Dim ruta As String

    Dim cliente

    Dim Respuesta

    NombreHoja = "VENTAS"

    FilasFactura = Application.WorksheetFunction.CountA(Range("FACTURA[CÓDIGO]"))

    NumFactura = ThisWorkbook.Sheets("PROFORMA").Range("C18").Value
    

    cliente = ThisWorkbook.Sheets("PROFORMA").Range("C15").Value

    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

    If FilasFactura = 0 Or Range("valCliente").Value = " " Then _

    MsgBox "Verifique que halla ingresado: cliente, codigo, cantidad y descuento.", vbExclamation, "INDUSTRIA ELECTRICA NEWLINE S.A.S ": Exit Sub

    'Propiedad FileDialog

        With Application.FileDialog(msoFileDialogFolderPicker)
    
            .InitialFileName = Application.DefaultFilePath & " \ "
    
            .Title = "INDUSTRIA ELECTRICA NEWLINE S.A.S - Seleccionar carpeta"
    
            .Show
    
            If .SelectedItems.Count = 0 Then
    
            Else
    
                ruta = .SelectedItems(1)
    
                      MsgBox "Guardando en PDF Orden de pedido N°'" & NumFactura & "'. Presione Aceptar para continuar...", _
    
                    vbInformation, "INDUSTRIA ELECTRICA NEWLINE S.A.S "
    
                    
    
                    ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
    
                    ruta & "\" & "Pedido  " & cliente & NumFactura & ".pdf", Quality:=xlQualityStandard, _
    
                    IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=True
    
                    
    
                     
    
                               
    
                     
    
            End If
    
        End With
    

    '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

    With ThisWorkbook.Sheets(NombreHoja)

    For i = 1 To FilasFactura
    
        Set HojaDestino = ThisWorkbook.Sheets(NombreHoja).Range("A1").CurrentRegion
    
        
    
        NuevaFila = HojaDestino.Rows.Count + 1
    
        .Cells(NuevaFila, 1).Value = NumFactura
    
        .Cells(NuevaFila, 2).Value = Range("FEC").Value
    
        .Cells(NuevaFila, 3).Value = Range("valCliente").Value
    
        .Cells(NuevaFila, 4).Value = Range("valNit").Value
    
        .Cells(NuevaFila, 14).Value = Range("FPAGO").Value
    
        .Cells(NuevaFila, 13).Value = Range("ciud").Value
    
        
    
           For j = 1 To 7
    
                .Cells(NuevaFila, j + 4).Value = ThisWorkbook.Sheets("PROFORMA").Cells(20 + i, 1 + j)
    
            Next j
    
            Next i
    

    End With

    MsgBox "Salvado", vbInformation, "INDUSTRIA ELECTRICA NEWLINE S.A.S "

    ThisWorkbook.Sheets("TD-Consulta-Factura").PivotTables("TDdetalle").PivotCache.Refresh
    

    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

    Respuesta = MsgBox("Deseas borrar los datos?", vbYesNo + vbQuestion, "EXCELeINFO")

    If Respuesta = vbYes Then
    
        With ThisWorkbook.Sheets("PROFORMA")
    
            
    
            .Range("B21:B40").ClearContents
    
            .Range("C21:C40").ClearContents
    
            
    
            .Range("C15:E15").ClearContents
    
    End With
    
    Else
    
    End If
    

    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

    End Sub

    Sub ConsultarFactura()

    Dim Factura

    Dim Imprimir As Integer

    Factura = InputBox("Ingresa la orden de pedido a consultar.", "Industria Electrica Newline SAS")

    Range("C18").Value = Factura

    Dim pt As PivotTable

    Dim pf As PivotField

    Dim pi As PivotItem

    On Error GoTo ManejadorErrores

    Set pt = ThisWorkbook.Sheets("TD-Consulta-Factura").PivotTables("TDdetalle")

    Set pf = pt.PivotFields("N° PEDIDO ")

    pf.ClearAllFilters

    For Each pi In pf.PivotItems

    If pi.Name = Factura Then
    
        pi.Visible = True
    
    Else
    
        pi.Visible = False
    
    End If
    

    Next pi

    Imprimir = MsgBox("Deseas imprimir la factura?", vbYesNo + vbQuestion, "Industria Electrica Newline SAS")

    If Imprimir = vbYes Then

    ActiveSheet.PrintOut Copies:=1
    

    Else

    End If

    Exit Sub

    ManejadorErrores:

    MsgBox "La factura " & Factura & " puede que no exista", vbExclamation, "Industria Electrica Newline SAS"

    Range("C18").ClearContents

    End Sub

    This is the only part of the code that I used recording macro to save files in PDFUser's image

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.