Disable all dialog boxes in Excel while running VBscript?

后端 未结 5 1628
旧巷少年郎
旧巷少年郎 2021-01-04 01:19

I have some code in VB that saves all XLSM files as XLSX. I already have the code that will do that for me, but dialog boxes show up for every action. This was fine for a fe

5条回答
  •  醉话见心
    2021-01-04 02:08

    Have you tried using the ConflictResolution:=xlLocalSessionChanges parameter in the SaveAs method?

    As so:

    Public Sub example()
    Application.DisplayAlerts = False
    Application.EnableEvents = False
    
    For Each element In sArray
        XLSMToXLSX(element)
    Next element
    
    Application.DisplayAlerts = False
    Application.EnableEvents = False
    End Sub
    
    Sub XLSMToXLSX(ByVal file As String)
        Do While WorkFile <> ""
            If Right(WorkFile, 4) <> "xlsx" Then
                Workbooks.Open Filename:=myPath & WorkFile
    
                Application.DisplayAlerts = False
                Application.EnableEvents = False
    
                ActiveWorkbook.SaveAs Filename:= _
                modifiedFileName, FileFormat:= _
                xlOpenXMLWorkbook, CreateBackup:=False, _
                ConflictResolution:=xlLocalSessionChanges
    
                Application.DisplayAlerts = True
                Application.EnableEvents = True
    
                ActiveWorkbook.Close
            End If
            WorkFile = Dir()
        Loop
    End Sub
    

提交回复
热议问题