vba - workaround for issue excel saving temp files

后端 未结 2 1856
情书的邮戳
情书的邮戳 2021-01-23 02:26

When saving a specific workbook, Excel creates a temp file instead of saving the data (without displaying an error or warning message). The symptoms are roughly the same as desc

2条回答
  •  难免孤独
    2021-01-23 03:06

    I tested this Sub in Excel 2010 and it works for me. I immediately break the loop after deleting the file as I assume the indexing may get out of alignment with the loop. A more refined variant might loop through the recent file list and create a collection of indices to delete, then iterate backward over that collection and delete each entry in turn.

    Public Sub RemoveRecentFile(strFileName As String)
    
        Dim collRecentFiles As Excel.RecentFiles
        Dim objRecentFile As Excel.RecentFile
        Dim intRecentFileCount As Integer
        Dim intCounter As Integer
    
        Set collRecentFiles = Application.RecentFiles
        intRecentFileCount = collRecentFiles.Count
    
        For intCounter = 1 To intRecentFileCount
            Set objRecentFile = collRecentFiles(intCounter)
            If objRecentFile.Name = strFileName Then
                objRecentFile.Delete
                Exit For
            End If
        Next intCounter
    
    End Sub
    

提交回复
热议问题