anthony

Public Schedule Face-to-Face & Online Instructor-Led Training - View dates & book

Forum home » Delegate support and help forum » Microsoft Excel VBA Training and help » Anthony

Anthony

resolvedResolved · 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 courses

 

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
What does 'Resolved' mean?

Any suggestions, questions or comments? Please post in the Improve the forum thread.


 

Excel tip:

Filtering Data in an Excel 2010 Worksheet

When 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.

You will now see arrows in the top row of all the columns. If you click on an arrow, it will give you some filtering options so you can sort your data into ''Smallest to Largest'' or ''Oldest to Newest'' and so on..

To turn off the filtering, go back to the Home tab and click the Filter button again.

View all Excel hints and tips


Server loaded in 0.08 secs.