首页 > 解决方案 > 关闭未保存的工作簿

问题描述

我正在尝试打开一个包含我打开的数据的(源)文件,将整个工作表移动到我的(目标)工作簿,更改(源)文件的位置,然后关闭(源)文件而不保存任何文件变化。当我使用 .xlsx 源文件时,我对此过程没有任何问题。当我突然将源文件更改为 .csv 时,当我关闭源文件时出现错误提示“运行时错误'-214722080 (800401a8)':自动化错误”在引发错误的行中,我已经还尝试执行“Set src = Workbooks.Close(false, filename)”,这给了我一个错误,说没有关键对象。

    fileExists = Dir(filename)
    'Checks the above command
    If fileExists = "" Then
        Exit Sub
    End If
    
    'Performance saving
    Application.ScreenUpdating = False
    
    'Setting the source workbook to the files from Ignition
    Dim src As Workbook
    Set src = Workbooks.Open(filename, True, True)
    
    'Pulling in the data from the file and then closing it without saving so the data isn't deleted from the file
    src.Sheets(1).Move After:=ThisWorkbook.Sheets("Overview")
    
    'Moves data that is already read in into the archive folder so it doesn't get in the way of future runs
    Name filename As path & "Archive\" & newk & "US1Data.csv"
    
    'Closes source workbook after its been moved, line that causes error
    src.Close savechanges:=False

标签: excelvba

解决方案


推荐阅读