선택한 폴더에있는 각 파일의 행 수를 계산 한 다음 활성 통합 문서에 표시하려면 VBA 스크립트를 실행하고 있습니다.VBA에서 셀의 파일 경로를 사용하는 방법?
Option Explicit
Sub CountRows()
Dim wbSource As Workbook, wbDest As Workbook
Dim wsSource As Worksheet, wsDest As Worksheet
Dim strFolder As String, strFile As String
Dim lngNextRow As Long, lngRowCount As Long
Application.ScreenUpdating = False
Set wbDest = ActiveWorkbook
Set wsDest = wbDest.ActiveSheet
strFolder = Dir(Range("C7").Value)
strFile = Dir(strFolder & "*.xlsx")
lngNextRow = 11
Do While Len(strFile) > 0
Set wbSource = Workbooks.Open(Filename:=strFolder & strFile)
Set wsSource = wbSource.Worksheets(1)
lngRowCount = wsSource.UsedRange.Rows.Count
wsDest.Cells(lngNextRow, "F").Value = lngRowCount
wbSource.Close savechanges:=False
lngNextRow = lngNextRow + 1
strFile = Dir
Loop
Application.ScreenUpdating = True
End Sub
폴더를 Chooing, 나는 스크립트에서 디렉토리를 작성하는 대신 현재 통합 문서의 셀에 "C7"에 삽입 된 디렉토리를 사용하고 싶습니다. 나는 대체하려고 :
strFolder = "C:\Users\user\Desktop\"
strFolder = Dir(Range("C7").Value)
로했지만 작동하지 않습니다. 어쩌면 누군가가 어떤 생각을 가지고 있을까요? 감사! 다음 (
C7
에서) 및 디렉토리에
워크 시트 ("wbName"). 범위 ("shName"). 범위 ("C7")' –
기대되는 다른 것이 있을지 모르겠다. :하지만 내게 ID는 "있는 그대로"작동했습니다. C : \ Users \ tstracke \ Desktop \ U-Wert-Rechner \ test 문서에서 셀 21에 번호 21이 삽입되었습니다. 21은 지정된 폴더에있는 한 문서의 행 수입니다. –
죄송합니다. 이해가 가지 않습니다. 내가 strFolder를 정확히 정의해야하는 방법은 무엇입니까? – Ale