파일을 여러 개 Excel 워크 북을 열고 마스터 파일로 복사하는 롤업 파일이 있습니다. 이 프로그램은 몇 달 동안 잘 실행되었지만 몇일 동안은 파일을 열 때 실패했습니다. 다음과 같은 오류 메시지가 나타납니다.VBA 파일을 열 수 없습니다.
런타임 오류 '1004':
파일 형식 또는 파일 확장자가 유효하지 않기 때문에 엑셀 파일 "filename.xlsm"를 열 수 없습니다. 파일이 손상되지 않았는지, 파일 확장명이 파일 형식과 일치하는지, 파일 확장명이 파일 형식과 일치하는지 확인하십시오.
디버그를 누르고 프로그램을 계속 실행하면 파일이 문제없이 열립니다. 프로그램을 다시 시작하면 파일을 열지 못하지만 그 파일은 절대 열리지 않습니다. 내가 그 (것)들로 들어가고 파일 연장이 정확한 때 실패 할 통합 문서에 어떤 문제든지 찾아 낼 수 없다. 현재 통합 문서에있는 것이 있는지 확인하기 위해 오류 처리 기능이 있으므로 생각할 수 없습니다.
도움이 되시길 바랍니다. 감사합니다.
If Not FileLocked(CStr(FoundFiles(iIndex))) Then
On Error GoTo contentErr
Workbooks.Open FoundFiles(iIndex) ', UpdateLinks:=xlUpdateLinksNever
On Error GoTo 0
Application.Run ("'Auto Update Roll-Up.xlsm'!Update")
With Workbooks(tempvar(iIndex - 1))
.Close False
LogInformation ("Completed " & tempvar(iIndex - 1) & " at " & Now)
'Application.EnableEvents = False
'.Close True
'Application.EnableEvents = True
End With
End If
Continue:
Next iIndex
On Error Resume Next
DisplayAlerts = False
Workbooks("Brickman Roll-Up Template.xlsm").Close savechanges:=True
'Workbooks("Brickman Roll-Up Template Test.xlsm").Close savechanges:=True
SetAttr rollupPath, vbReadOnly
Workbooks("Auto Update Roll-Up.xlsm").Close savechanges:=False
DisplayAlerts = True
LogInformation ("Program ended at " & Now)
Application.Quit
contentErr:
If Err.Number = 1004 Then
LogInformation ("_______There is unreadable content in " & Chr(34) & tempvar(iIndex - 1) & Chr(34) & "_______")
GoTo Continue
End If
End Sub
Function FileLocked(strFileName As String) As Boolean
On Error Resume Next
' If the file is already opened by another process,
' and the specified type of access is not allowed,
' the Open operation fails and an error occurs.
Open strFileName For Binary Access Read Write Lock Read Write As #1
Close #1
' If an error occurs, the document is currently open.
If Err.Number <> 0 Then
' Display the error number and description.
LogInformation ("Couldn't open " & strFileName & " because it is already checked out.")
FileLocked = True
Err.Clear
End If
End Function
오류가 Workbooks.Open의 FoundFiles (iIndex가)
추가? 그 기능에 문제가 있습니다 ... –