0

我目前有一个删除用户表单中文件的代码。我输入一个参考,这个术语填充到一个工作表中,所有的计算都被计算出来了。

我要做的是删除旧的现有文档,然后保存标题中带有“CLOSED”一词的新副本。我觉得这段代码应该可以工作,但看不出它为什么找不到指定的文件。

Sub CloseDoc()

Dim FSO
Dim sFile As String

sFile = "M:\Documents\" & Range("B3").Text & " - " & Range("B14").Text & ".xlsx"
Set FSO = CreateObject("Scripting.FileSystemObject")

If FSO.FileExists(sFile) Then
    FSO.DeleteFile sFile, True
        MsgBox "Deleted The File Successfully, Ready to update with CLOSED information", vbInformation, "Done!"
    Else
        MsgBox "Specified File Not Found", vbInformation, "Not Found!"
End If

    Sheets("ITC").Copy

    Range("A1:B54").Select
        Application.CutCopyMode = False
        Selection.Copy
        ActiveWindow.SmallScroll Down:=-60
        Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
            :=False, Transpose:=False
        Range("A1").Select
'Save Document to Dir
    ActiveWorkbook.SaveAs Filename:= _
        "M:\Documents\" & Range("B3").Text & " - " & Range("B14").Text & " - CLOSED" & " .xlsx", FileFormat _
        :=xlOpenXMLWorkbook, CreateBackup:=False
    ActiveWorkbook.Close

    End Sub
4

0 回答 0