계속이 1004 런타임 오류가 발생합니다. 내 프로그래밍 방식을 약간 줄여서 Programception이 아니 었습니다. Excel 2010을 사용하여 .xls 파일을 저장해야 할 수도 있습니다. 확실하지 않다. Auto_Root.xls가 열리면파일을 열고 값으로 저장하는 매크로를 실행하는 매크로 - 런타임 오류 1004
- 는 순차적으로 다른 디렉토리에 7 개 파일 을 열고 하위 업데이트를() Panel.xls
- 패널이 열리고 열리고 실행 하위에 Auto_Open()를 실행하는 모든라는 Auto_Update.xls
- Auto_Update.xsl은 각각 개의 파일을 순차적으로 열어 자신의 플랫 복사본을 다른 디렉터리에 저장하는 Sub Flat을 열고 실행합니다.
7 개의 Auto_Update.xls 파일을 각각 열어서 독립적으로 실행 했으므로 오류없이 실행됩니다. Auto_Root에서 모두 실행하면 런타임 오류 1004가 발생합니다. 그리고 CurrentWB.Save는 파일 중 하나에서 강조 표시됩니다. 나는 CurrentWB.Save를 CurrentWB.SaveAs Filename : = TargetFile, FileFormat : = xlNormal로 대체하고 동일한 런타임 오류를 수신했습니다.
첨부 된 코드는 있습니다.
AutoRoot.xls! 자동 업데이트
Sub auto_open()
Application.CutCopyMode = False
Dim PanelFilePath As String
Dim PanelFileName As String
Dim PanelLocation As String
Dim PanelWB As Workbook
PanelFilePath = "D:\umc\UMC Production Files\Automation Files\"
PanelFileName = "Panel.xls"
PanelLocation = PanelFilePath & Dir$(PanelFilePath & PanelFileName)
Set PanelWB = Workbooks.Open(Filename:=PanelLocation, UpdateLinks:=3)
PanelWB.RunAutoMacros Which:=xlAutoOpen
Application.Run "Panel.xls!Update"
PanelWB.Close
Call Shell("D:\umc\UMC Production Files\Automation Files\Auto.bat", vbNormalFocus)
Application.Quit
End Sub
Panel.xls! 업데이트
Sub Update()
Dim RowNumber As Long
Dim AutoUpdateTargetFile As String
Dim AutoUpdateWB As Workbook
For RowNumber = 1 To (Range("AutoUpdate.File").Rows.Count - 1)
If (Range("AutoUpdate.File").Rows(RowNumber) <> "") Then
AutoUpdateTargetFile = Range("Sys.Path") & Range("Client.Path").Rows(RowNumber) & Range("AutoUpdate.Path ").Rows(RowNumber) & Range("AutoUpdate.File").Rows(RowNumber)
Set AutoUpdateWB = Workbooks.Open(Filename:=AutoUpdateTargetFile, UpdateLinks:=3)
AutoUpdateWB.RunAutoMacros Which:=xlAutoOpen
Application.Run "Auto_Update.xls!Flat"
AutoUpdateWB.Close
End If
Next RowNumber
End Sub
AutoUpdate.xls!
Sub Flat()
Dim RowNumber As Long 'Long Stores Variable
Dim SheetNumber As Long
Dim TargetFile As String 'String Stores File Path
Dim BackupFile As String
Dim CurrentWB As Workbook 'Workbook Stores Workbook
For RowNumber = 1 To (Range("File").Rows.Count - 1)
'Loops through each file in the list and assigns a workbook variable.
If (Range("File").Rows(RowNumber) <> "") Then
TargetFile = Range("Sys.Path") & Range("Path").Rows(RowNumber) & Range("File").Rows(RowNumber) 'Target File Path
BackupFile = Range("Report.Path") & Range("Path").Rows(RowNumber) & Range("SubFolder") & Range("File").Rows(RowNumber) 'Backup File Path
Set CurrentWB = Workbooks.Open(Filename:=TargetFile, UpdateLinks:=3) 'Sets CurrentWB = to that long name. This becomes the name of the workbook.
CurrentWB.RunAutoMacros Which:=xlAutoOpen 'Enables Macros in Workbook
CurrentWB.SaveAs Filename:=TargetFile, FileFormat:=56
For SheetNumber = 1 To Sheets.Count 'Counts Worksheets in Workbook
Sheets(SheetNumber).Select 'Selects All Worksheets in Workbook
If (Sheets(SheetNumber).Name <> "What If") Then
Sheets(SheetNumber).Unprotect ("UMC626") 'Unprotects Workbook
Cells.Select 'Selects Data in Workbook
Range("B2").Activate
With Sheets(SheetNumber).UsedRange
.Value = .Value
End With
Sheets(SheetNumber).Protect Password:="UMC626", DrawingObjects:=True, Contents:=True, Scenarios:=True 'Protects Workbook
End If
Next SheetNumber 'Runs Through Iteration
Sheets(1).Select
Range("A1").Select 'Saves each workbook at the top of the page
CurrentWB.SaveAs Filename:=BackupFile, FileFormat:=56, Password:="", WriteResPassword:="", _
ReadOnlyRecommended:=False, CreateBackup:=False 'Saves Workbook in Flatten File Location
CurrentWB.Close 'Closes Workbook
End If 'Ends Loop
Next RowNumber 'Selects Another Account
End Sub
플랫 내가 지금까지했던 어떤.
- 각 개별 자동 업데이트 파일은 켜져있을 때 작동합니다.
- Application.Run "Auto_Update.xls! Flat"이 Panel.xls! Update에서 제거되면 모든 AutoUpdate.xls 파일이 오류없이 열리고 닫힙니다.
- Panel.xls! 7 AutoUpdate 파일 중 3 개만 업데이트하면 .... 3. 아무런 오류없이 실행됩니다.
난 그냥 코드 주위에 마이크로 소프트 작품을 발견 런타임 오류 (1004)
말을하지 않고 모든 7을 실행 얻을 수없는 것. 비록 그것을 구현하는 방법을 잘 모르겠습니다.
Sub CopySheetTest()
Dim iTemp As Integer
Dim oBook As Workbook
Dim iCounter As Integer
' Create a new blank workbook:
iTemp = Application.SheetsInNewWorkbook
Application.SheetsInNewWorkbook = 1
Set oBook = Application.Workbooks.Add
Application.SheetsInNewWorkbook = iTemp
' Add a defined name to the workbook
' that RefersTo a range:
oBook.Names.Add Name:="tempRange", _
RefersTo:="=Sheet1!$A$1"
' Save the workbook:
oBook.SaveAs "c:\test2.xls"
' Copy the sheet in a loop. Eventually,
' you get error 1004: Copy Method of
' Worksheet class failed.
For iCounter = 1 To 275
oBook.Worksheets(1).Copy After:=oBook.Worksheets(1)
'Uncomment this code for the workaround:
'Save, close, and reopen after every 100 iterations:
If iCounter Mod 100 = 0 Then
oBook.Close SaveChanges:=True
Set oBook = Nothing
Set oBook = Application.Workbooks.Open("c:\test2.xls")
End If
Next
End Sub
http://support.microsoft.com/kb/210684/en-us
어떤 줄이 오류를 발생 시키나요? –
'File'및 'Path'의 NAMED 범위를 올바르게 정의하고 ONE 셀의 이름을 'Sys.Path', 'Report.Path'및 'SubFolder'로 지정 했습니까? 또한, 'Sys.Path'(및 기타 정보)에 어떤 값을 가지고 있습니까? –
통합 문서에 읽기 전용 속성이 설정되어 있습니까? – Sorceri