Leena has attended:
Excel VBA Intro Intermediate course
Anthony
Hello, can you please send over the code that you wrote around opening workbooks within a folder?
Thanks,
Leena
RE: Anthony
Hi Leena, good to hear from you. Here's the code we discussed, be sure to point it at your specific folder and try to run it on a relatively fast machine.
----------------------
Sub GetMyData()
Dim wbOpen As Workbook
Const strPath As String = "C:\test\" '<-------Cabinet Office change accordingly
Dim strExtension As String
Dim myValue As String
Dim intTargetrowcount As Integer
intTargetrowcount = 1
Application.ScreenUpdating = False
Application.DisplayAlerts = False
ChDir strPath
'Change extension
strExtension = Dir(strPath & "*.xls")
Do While strExtension <> ""
Set wbOpen = Workbooks.Open(strPath & strExtension)
'MsgBox wbOpen.Sheets("mydata").Cells(10, 4).Value
'*************************************************************
'Cabinet Office - alter the following code to tailor to your forms:
'dump the value from the returned form into a variable
'do this (with multiple variables) for multiple form results if necessary
myValue = wbOpen.Sheets("MyData").Range("d10").Value
'close down the form
wbOpen.Close SaveChanges:=False
'add the collected value to your results sheet:
Sheets("Results").Cells(intTargetrowcount, 1).Value = myValue
'and don't forget to create a new row for each returned form
intTargetrowcount = intTargetrowcount + 1
'*************************************************************
strExtension = Dir
Loop
Application.ScreenUpdating = True
Application.DisplayAlerts = True
End Sub
----------------------
Hope this helps,
Anthony