Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default Cycle Excel Files Linking & Summing

Hi, I need help with a bit of code that cycles through every Excel file in a
single folder, and copies the filename and links the last value in columns C,
E, F & G, such that I end up with a seperate Excel file showing:

Name | C | E | F | G |


I can do it for every worksheet, but am not sure how to do it for every file
in a given folder. The folder location will not change.

Dave
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default Cycle Excel Files Linking & Summing

If I understand your code correctly, I should be able to stick my code inside
the For loop. I'll give it a go and see what happens.

Thanks

Dave

"Martin" wrote:

As far as I know, you'll need to open every file. Here's a routine I use to
list all files with a given extension in a particular folder (it's a Word
macro but you can ignore the end bit). You should be able to pull the bits
you need from it and use a Workbooks.Open statement in a loop to open them
all:

Sub ListFilesInFolder()
Dim myPath As String
Dim myPrefix As String
Dim myExt As String
myPath = InputBox("Path?")
myPrefix = InputBox("Any prefix?")
myExt = InputBox("File extension?", , ".xls")
Dim fs, f, f1, fc
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.GetFolder(myPath)
Set fc = f.Files
For Each f1 In fc
If LCase(Right(Trim(f1.Name), 4)) = myExt Then
Selection.TypeText myPrefix & f1.Name
Selection.TypeParagraph
End If
Next
End Sub


"David M C" wrote:

Hi, I need help with a bit of code that cycles through every Excel file in a
single folder, and copies the filename and links the last value in columns C,
E, F & G, such that I end up with a seperate Excel file showing:

Name | C | E | F | G |


I can do it for every worksheet, but am not sure how to do it for every file
in a given folder. The folder location will not change.

Dave

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 336
Default Cycle Excel Files Linking & Summing

As far as I know, you'll need to open every file. Here's a routine I use to
list all files with a given extension in a particular folder (it's a Word
macro but you can ignore the end bit). You should be able to pull the bits
you need from it and use a Workbooks.Open statement in a loop to open them
all:

Sub ListFilesInFolder()
Dim myPath As String
Dim myPrefix As String
Dim myExt As String
myPath = InputBox("Path?")
myPrefix = InputBox("Any prefix?")
myExt = InputBox("File extension?", , ".xls")
Dim fs, f, f1, fc
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.GetFolder(myPath)
Set fc = f.Files
For Each f1 In fc
If LCase(Right(Trim(f1.Name), 4)) = myExt Then
Selection.TypeText myPrefix & f1.Name
Selection.TypeParagraph
End If
Next
End Sub


"David M C" wrote:

Hi, I need help with a bit of code that cycles through every Excel file in a
single folder, and copies the filename and links the last value in columns C,
E, F & G, such that I end up with a seperate Excel file showing:

Name | C | E | F | G |


I can do it for every worksheet, but am not sure how to do it for every file
in a given folder. The folder location will not change.

Dave

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default Cycle Excel Files Linking & Summing

Looks good. Thanks. The rest should be easy.

Dave

"Martin" wrote:

Sort of - I've tweaked it as follows (with the Workbooks().Close statement in
case you end up with too many files open at once):

Sub OpenAllFilesInFolder()
Dim myPath As String
myPath = InputBox("Path?")
Dim fs, f, f1, fc
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.GetFolder(myPath)
Set fc = f.Files
For Each f1 In fc
If LCase(Right(Trim(f1.Name), 4)) = ".xls" Then
Workbooks.Open myPath & f1.Name
[your code for active workbook]
Workbooks(f1.Name).Close
End If
Next
End Sub


"David M C" wrote:

If I understand your code correctly, I should be able to stick my code inside
the For loop. I'll give it a go and see what happens.

Thanks

Dave

"Martin" wrote:

As far as I know, you'll need to open every file. Here's a routine I use to
list all files with a given extension in a particular folder (it's a Word
macro but you can ignore the end bit). You should be able to pull the bits
you need from it and use a Workbooks.Open statement in a loop to open them
all:

Sub ListFilesInFolder()
Dim myPath As String
Dim myPrefix As String
Dim myExt As String
myPath = InputBox("Path?")
myPrefix = InputBox("Any prefix?")
myExt = InputBox("File extension?", , ".xls")
Dim fs, f, f1, fc
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.GetFolder(myPath)
Set fc = f.Files
For Each f1 In fc
If LCase(Right(Trim(f1.Name), 4)) = myExt Then
Selection.TypeText myPrefix & f1.Name
Selection.TypeParagraph
End If
Next
End Sub


"David M C" wrote:

Hi, I need help with a bit of code that cycles through every Excel file in a
single folder, and copies the filename and links the last value in columns C,
E, F & G, such that I end up with a seperate Excel file showing:

Name | C | E | F | G |


I can do it for every worksheet, but am not sure how to do it for every file
in a given folder. The folder location will not change.

Dave

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Linking Excel Files Salman Excel Discussion (Misc queries) 2 September 1st 08 01:03 PM
How do I keep result from 1 iteration cycle to use in next cycle? sgl8akm Excel Discussion (Misc queries) 0 July 27th 06 08:28 PM
Cycle Excel Files Linking & Summing Martin Excel Programming 0 March 20th 06 02:50 PM
Cycle through a folder of excel files Chet[_2_] Excel Programming 1 September 21st 04 10:05 PM
Linking two Excel Files Tslaby Excel Programming 3 December 1st 03 07:27 PM


All times are GMT +1. The time now is 09:15 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"