Thread
:
Open all files in folder automatically using VBA
View Single Post
#
5
Posted to microsoft.public.excel.programming
William[_2_]
external usenet poster
Posts: 227
Open all files in folder automatically using VBA
Just to add to Dave's point....
If you want to actually select a cell within the workbook opened (which is
unnecessary 99% of the time), you should select the worksheet first and then
the cell, so....
---------------
wb.Worksheets(1).Select
wb.Worksheets(1).Range("A1").Select
---------------
--
XL2003
Regards
William
"Dave Peterson" wrote in message
...
Maybe you don't have a worksheet named "sheet1" for each of those
workbooks.
If you wanted the leftmost worksheet, maybe you could use:
wb.Worksheets(1).Range("A1").Select
wrote:
Thanks for the help William....I appreciate it!
I do have one problem with the code. I am getting a "Run-time error
'9': Subscript out of range" error when I try to run this code. Here
is the code:
Sub openfilesInALocation()
Dim i As Integer, wb As Workbook
With Application.FileSearch
.NewSearch
.LookIn = "C:\Documents and Settings\chrisf\My Documents\vbatest"
.SearchSubFolders = False
.Filename = "*.xls"
.Execute
For i = 1 To .FoundFiles.Count
'Open each workbook
Set wb = Workbooks.Open(Filename:=.FoundFiles(i))
'Perform the operation on the open workbook
----------- Errors on the following line:
wb.Worksheets("sheet1").Range("A1").Select
'Save and close the workbook
wb.Save
wb.Close
'On to the next workbook
Next i
End With
End Sub
If anyone can solve this for me I would appreciate the help!
-Chris
--
Dave Peterson
Reply With Quote
William[_2_]
View Public Profile
Find all posts by William[_2_]