PDA

View Full Version : Solved: Opening unknown File names in known Folder



jazzyt2u
07-03-2008, 10:20 AM
Hi,

I'm wondering if there is coding that can open files in a folder one at a time to make changes. Then close that file and go to the next file in the folder until all files have been adjusted. I will only know the folder location not the names of the files.

Please help...working on project.

jazzyt2u
: pray2:

Bob Phillips
07-03-2008, 10:25 AM
Sub OpenFiles()
Const FOLDER_NAME As String = "C:\test\" '<===== change to suit
Dim NextFile As String

NextFile = Dir(FOLDER_NAME & "*.xls", vbNormal)
Do While NextFile <> ""

Workbooks.Open FOLDER_NAME & NextFile
'do stuff on active workbook
NextFile = Dir
Loop
End Sub

jazzyt2u
07-03-2008, 10:30 AM
Yeah!!!!!!!!:rotlaugh:

jazzyt2u
07-07-2008, 09:52 AM
Is there a way to find out each excel file name once I've opened the file? The reason I ask is because I will be opening a Word template and would like to save that word template using the same name as each excel file I work in.

Bob Phillips
07-07-2008, 10:42 AM
Yes, the filename is called Name, a property of the workbook, so for example



MsgBox ActiveWorkbook.Name