Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
M M is offline
external usenet poster
 
Posts: 18
Default HELP: Link all values in a workbook under same folder on one sheet

Hi there!

Am doing a consolidation macro that will require me to
sum all values in a specific cell (e.g. A1), under same
worksheet (e.g Sheet1) of all the workbooks (of
indefinite number) found under one folder.

Can anyone provide me a sample script can use? Tnx a
bunch! =)
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 20
Default Link all values in a workbook under same folder on one sheet

Hi !

You can try the following code to:
- loop through a folder
- Open all .xls files
- Loop through the sheets
- Save and close the workbook



Sub LoopFolder()

Dim FileName As String
Dim FindDirectory As String

FindDirectory = "C:\Temp\" 'Put your foldername here

FileName = Dir(FindDirectory, vbNormal)
Do While FileName < ""
If Right(FileName, 4) = ".xls" Then
Workbooks.Open FileName:=FindDirectory & FileName
'Do whatever you have to do withe the workbook, for example:
For Each sh In ActiveWorkbook.Sheets
Debug.Print FileName & " - " & sh.Name
Next sh
ActiveWorkbook.Close savechanges:=True
End If
FileName = Dir
Loop

End Sub


"m" wrote in message
...
Hi there!

Am doing a consolidation macro that will require me to
sum all values in a specific cell (e.g. A1), under same
worksheet (e.g Sheet1) of all the workbooks (of
indefinite number) found under one folder.

Can anyone provide me a sample script can use? Tnx a
bunch! =)



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 52
Default Link all values in a workbook under same folder on one sheet

Hello m
Here's a try (amend sheet name and path)
(please note that workbook containing code should NOT be in same directory
as files searched)
Option Base 1
Sub Consolider()
With Application.FileSearch
..NewSearch
..LookIn = "C:\DOC\Robi10\Doc\Excel\Tests\MPFE"
..FileType = msoFileTypeExcelWorkbooks
If .Execute() < 0 Then
Dim Part1, Part2, SourceFile$, n&, AntiSlashPos&, FileNamesArray()
For i = 1 To .FoundFiles.Count
'Define array bounds
ReDim Preserve FileNamesArray(1 To .FoundFiles.Count)
'Now build the correct syntax to consolidate:
n = Len(.FoundFiles(i)) - Len(Replace(.FoundFiles(i), "\", ""))
AntiSlashPos = Position(.FoundFiles(i), n)
'Part1 = full path
Part1 = Mid(.FoundFiles(i), 1, AntiSlashPos)
'Part2 = filename only
Part2 = Mid(.FoundFiles(i), AntiSlashPos + 1, Len(.FoundFiles(i)) -
AntiSlashPos)
SourceFile = "'" & Part1 & "[" & Part2 & "]Feuil1'!R1c1"
FileNamesArray(i) = SourceFile
'End If
Next i
ThisWorkbook.Sheets("Feuil1").Range("A1").Consolid ate Sources:= _
Array(FileNamesArray()), Function:=xlSum, _
TopRow:=False, LeftColumn:=False, CreateLinks:=True
End If
End With
End Sub
'returns position of Antislash from a path info
Function Position(Chemin$, Nb&) As Long
Dim Pos1 As Long
Dim Pos2 As Long
Dim i As Long
Pos2 = 0
For i = 1 To Nb
Pos1 = Pos2
Pos2 = InStr(Pos1 + 1, Chemin, "\")
If Pos2 = 0 Then Exit For
Next i
If Pos2 Pos1 Then
Position = Pos2
Else
Position = 0
End If
End Function

HTH
Cordially
Pascal


"m" a écrit dans le message de
...
Hi there!

Am doing a consolidation macro that will require me to
sum all values in a specific cell (e.g. A1), under same
worksheet (e.g Sheet1) of all the workbooks (of
indefinite number) found under one folder.

Can anyone provide me a sample script can use? Tnx a
bunch! =)



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
how do I link to another sheet in workbook? Pmsrefugee Excel Discussion (Misc queries) 12 February 25th 10 04:49 AM
Link with workbook in other folder which is in another group Frank Situmorang Excel Discussion (Misc queries) 3 April 5th 07 05:50 AM
move a sheet out of my workbook and place in another folder? trishb123 Excel Discussion (Misc queries) 3 January 10th 07 04:14 PM
Link individual sheet to one sheet in another workbook dfield Excel Discussion (Misc queries) 1 March 12th 06 02:26 AM
Excel how do I link text values in one sheet to another sheet? chrisjtm Excel Discussion (Misc queries) 3 March 9th 06 06:09 AM


All times are GMT +1. The time now is 06:54 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"