98.7% Of all customers recommend us, we're so confident about our results we publish all reviews and stats
View Live Stats View ReviewsForum home » Delegate support and help forum » Microsoft Excel VBA Training and help » Anthony
Anthony
Resolved · Low Priority · Version 2007
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
Training information:
Welcome. Please choose your application (eg. Excel) and then post your question. Our Microsoft Qualified trainers will then respond within 24 hours (working days). Frequently Asked Questions
Any suggestions, questions or comments? Please post in the Improve the forum thread. |
Excel tip:Filtering Data in an Excel 2010 WorksheetWhen you have an Excel Worksheet with masses of data, it's not going to be easy to sift through it. So, in order to view sections of data, you can use the filter tool. Select the cells you want to filter (no need to select the column headers), then click the Home tab on the Ribbon, click Sort and Filter (you will find this in the Editing Section) then click Filter. |