jflaurin
Technical User
- Dec 1, 2007
- 12
The code below is suppose to loop thru all the files located where the master file is and extract the value in B2 and copy it in the master file. I'm getting a file not found error at this line of code :
Set wb = Workbooks.Open(strFile, ReadOnly = True)
here's the code :
<code>
Private Sub CommandButton1_Click()
Dim strFile As String, strFolder As String, lngRow As Long
Dim ws As Worksheet, wb As Workbook
strFolder = ActiveWorkbook.Path & "\"
lngRow = 1 'Starting row number in master file
Set ws = ActiveSheet
Application.ScreenUpdating = False
strFile = Dir(strFolder & "*.xls", vbNormal)
Do While strFile <> ""
Set wb = Workbooks.Open(strFile, ReadOnly = True)
ws.Range("A" & lngRow) = wb.ActiveSheet.Range("B2").Value
lngRow = lngRow + 1
wb.Close False
Set wb = Nothing
strFile = Dir
Loop
Application.ScreenUpdating = True
End Sub
</code>
Set wb = Workbooks.Open(strFile, ReadOnly = True)
here's the code :
<code>
Private Sub CommandButton1_Click()
Dim strFile As String, strFolder As String, lngRow As Long
Dim ws As Worksheet, wb As Workbook
strFolder = ActiveWorkbook.Path & "\"
lngRow = 1 'Starting row number in master file
Set ws = ActiveSheet
Application.ScreenUpdating = False
strFile = Dir(strFolder & "*.xls", vbNormal)
Do While strFile <> ""
Set wb = Workbooks.Open(strFile, ReadOnly = True)
ws.Range("A" & lngRow) = wb.ActiveSheet.Range("B2").Value
lngRow = lngRow + 1
wb.Close False
Set wb = Nothing
strFile = Dir
Loop
Application.ScreenUpdating = True
End Sub
</code>