Hi Everyone,
I have a lot of excel files in a folder that need to be evaluated as keep or
archive. Many have different names but are just different versions of the
same file....I am going to print all the files out and have our group
decide. I want the file name and location on each file. I know how to
insert this one at a time but is there a way to insert this function on all
of them at once?
Thanks,
Linda
JP - 04 Apr 2008 02:26 GMT
One way is a VBA routine that loops through the folder, opens each
file in turn and inserts the filename/path into a specified cell.
Crude but effective. You might want to post your request in microsoft.
public.excel.programming as this is a general Excel group.
HTH,
JP
> Hi Everyone,
>
[quoted text clipped - 7 lines]
> Thanks,
> Linda
Linda (RQ) - 04 Apr 2008 04:19 GMT
Thanks JP.
One way is a VBA routine that loops through the folder, opens each
file in turn and inserts the filename/path into a specified cell.
Crude but effective. You might want to post your request in microsoft.
public.excel.programming as this is a general Excel group.
HTH,
JP
On Apr 3, 2:45 pm, "Linda RQ" <RomulanQu...@Work.SSTNG> wrote:
> Hi Everyone,
>
[quoted text clipped - 9 lines]
> Thanks,
> Linda
Brian - 06 Apr 2008 06:54 GMT
(I'm new to this, so this might be a duplicate response)
I tested the code below and I think it does what you are asking.
First:
Open a new file
Select a cell (I used b2 on sheet1)
From the menu select Insert/Name/Define
Enter the text: Folder_Location
In the cell you just name, enter the folder path of your files.
Example: C:\Documents and Settings\My Documents\exel_stuff
Next:
Open the visual basic editor by pressing keys {alt}+{f11}
Copy the code below.
The code as is just displays your printout. Top print, put an apostrophe in
front of the line:
Sheets.PrintPreview
and remove the apostrophe in front of the line:
' Sheets.PrintOut
Try viewing it first to see if it does what you want. You can press keys
{ctrl}+{break} to stop it.
If you want to save the changes with the path etc, remove the apostrophe in
front of the line:
' ActiveWorkbook.Save
This will change the file save date so you may not want to do this.
Everything above this line is just info if you need it.
'********************************************************
Sub printfile()
Dim Folder
Dim fs, ws
Folder = Range("Folder_Location").Value 'b2 on sheet1
Set fs = Application.FileSearch
With fs
.LookIn = Folder
.Filename = "*.xls"
If .Execute(SortBy:=msoSortByFileName, _
SortOrder:=msoSortOrderAscending) > 0 Then
For i = 1 To .FoundFiles.Count
Workbooks.Open (.FoundFiles(i))
For Each ws In Worksheets
'Run tools/macro and setup the header and footer. Pick the values you
want changed and add to list below
'This addes the file path and name to the bottom left
With ws.PageSetup
'.LeftHeader = ""
'.CenterHeader = ""
'.RightHeader = ""
.LeftFooter = .LeftFooter & Chr(10) & "&Z&F" 'preserves existing
value and addes file path and name to end
'.CenterFooter = ""
'.RightFooter = ""
End With
Next ws
Sheets.PrintPreview ' select sheets sheets.printout to print instead of
preview
' Sheets.PrintOut
' ActiveWorkbook.Save 'if you want to save the changes, include this.
Often you want to keep original file date
ActiveWorkbook.Close
Next i 'process next file
Else
MsgBox "There were no files found."
End If
End With
End Sub
url:http://www.ureader.com/msg/102712600.aspx