
300개의 닫힌 통합 문서에서 데이터를 가져오는 수식을 작성하는 데 도움을 주세요(그리고 저는 그 300개의 통합 문서 중 어느 것도 열고 싶지 않습니다). 프로젝트 설명: 300개의 Excel 작업표가 있습니다. 각 작업표의 범위(A1:AC51)를 기본 계산 통합 문서에 복사하고 급여를 계산한 다음 급여 결과를 동일한 기본 통합 문서의 다른 워크시트에 복사해야 합니다. 여기서의 비결은 300개의 Excel 작업표를 열지 않고 작업을 수행하는 것입니다. 아래 코드를 작성했지만 닫힌 통합 문서에서 데이터를 가져오는 수식을 작성하는 방법에서 막혔습니다. 도와주세요. 다시,
- 300개의 Excel 작업표(닫힌 통합 문서), Sheets("EmpInput")가 있습니다.
- 주요 계산 통합 문서(열림)가 하나 있는데, Sheets("Main")입니다.
- 목표: 각 작업표에서 정확히 동일한 범위를 복사하고, 급여를 계산하고, 결과를 다른 시트인 Sheets("Results")에 복사합니다.
미리 감사드립니다!
Public Sub GetTimesheetData()
Dim fsoFileObject As New Scripting.FileSystemObject
Dim employeeTimesheet As File
Dim folderPath As String
Dim nextEmpty As Long
folderPath = "C:\GatherTimesheets\" '<<<<< There are 300 excel timesheets in this folder.
For Each employeeTimesheet In fso.folderPath.Files '<<<< Is this correct?
If empoyeeTimesheet.Name Like "*.xls" Then
Sheets("Main").Select
With Range("A1:AC51")
.Formula = "='C:\GatherTimesheets\" & employeeTimesheet '<<<< How to write this formula??
.Value = .Value
End With
nextEmpty = Sheets("Results").Range("D65444").End(xlUp).Row + 1
Sheets("Main").Range("CS1:DF1").Copy
With Sheets("StagingRaw").Range("D" & nextEmpty)
.PasteSpecial xlValues
Application.CutCopyMode = False
End With
End If
Next employeeTimesheet
End Sub
답변1
형식은 입니다 ='C:\Path\[SourceFileName.xlsx]SourceSheetName'!A1:Z9
.
노력하다 Range("A1:AC51").FormulaArray = "='C:\GatherTimesheets\[" & employeeTimesheet & "]EmpInput'!A1:AC51"
.
자세한 내용은 다음을 참조하세요.Range.FormulaArray 속성(Excel)그리고다른 통합 문서의 셀 범위에 대한 외부 참조(링크) 만들기. 또한,옵션 명시적와 같은 오타를 피하기 위해 empoyeeTimesheet
.