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

anthony

ResolvedVersion 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:

Manually rotating a 3D chart

To manually rotate a 3D chart;
Select the chart (edit mode) and click on one corner of the chart display area. A selection border will appear, using the left mouse button on one of the chart's "corners" (mouse pointer changes to a cross) drag the image which becomes a line representation of the chart (as you begin to drag) and rotate the chart to a view of your choice.
If you dont get it right first time, dont worry, the manoeuver is a little bit tricky.

View all Excel hints and tips

Connect with us:

0207 987 3777

Call for assistance

Request Callback

We will call you back

Server loaded in 0.09 secs.