Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Open all excel files in the "volatile" folder

Hello guys,

I wonder if it's possible to make a macro that will open all excel
files from the directory where the file I'll use for macro launching is
stored.

F. ex.: If I put my excel file with macro on desktop (and then run the
macro), it'll open all excel files that are on desktop. Then, if I'll
move this file to the folder D:/My Folder and re-run the macro, it'll
open all the excel files that are in D:/My Folder.

So, the goal would be to modify the below-mentionned macro in its
fourth line
---------------------------------------------------
Sub openAllfilesInALocation()
Dim i As Integer, wb As Workbook
With Application.FileSearch
..NewSearch
..LookIn = "D:\My Folder"

'= instead of a precise, fixed location, it should give "location
where the current excel file is
'saved"

..SearchSubFolders = False
..Filename = "*.xls"
..Execute
For i = 1 To .FoundFiles.Count
'Open each workbook

'= Probably I should put here some "if" code in order not to re-open
the file I'm currently using,
'like If wbk.Name < ThisWorkbook.Name /.../ End If
'can you confirm?

Set wb = Workbooks.Open(Filename:=.FoundFiles(i))
Next i
End With
End Sub
---------------------------------------------------

Thanks for any help on this...
Mark

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default Open all excel files in the "volatile" folder

Private Sub OpenFiles()
Dim sPath as string, sName as String
sPath = thisworkbook.Path
if right(sPath,1) < "\" then _
sPath = sPath & "\"
sname = dir(sPath & "*.xls")
do while sName < ""
if sName < thisworkbook.name then
workbooks.Open sPath & sName
end if
sName = dir()
Loop
end Sub

Call this from the workbook.Open event if you want it to be fired when the
workbook is opened.



--
Regards,
Tom Ogilvy

" wrote:

Hello guys,

I wonder if it's possible to make a macro that will open all excel
files from the directory where the file I'll use for macro launching is
stored.

F. ex.: If I put my excel file with macro on desktop (and then run the
macro), it'll open all excel files that are on desktop. Then, if I'll
move this file to the folder D:/My Folder and re-run the macro, it'll
open all the excel files that are in D:/My Folder.

So, the goal would be to modify the below-mentionned macro in its
fourth line
---------------------------------------------------
Sub openAllfilesInALocation()
Dim i As Integer, wb As Workbook
With Application.FileSearch
..NewSearch
..LookIn = "D:\My Folder"

'= instead of a precise, fixed location, it should give "location
where the current excel file is
'saved"

..SearchSubFolders = False
..Filename = "*.xls"
..Execute
For i = 1 To .FoundFiles.Count
'Open each workbook

'= Probably I should put here some "if" code in order not to re-open
the file I'm currently using,
'like If wbk.Name < ThisWorkbook.Name /.../ End If
'can you confirm?

Set wb = Workbooks.Open(Filename:=.FoundFiles(i))
Next i
End With
End Sub
---------------------------------------------------

Thanks for any help on this...
Mark


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 prevent Excel 2007 from leaving ".tmp" files in my folder Deb M Excel Discussion (Misc queries) 5 June 4th 09 07:16 PM
Excel not recognized using "open with" command on text files mrwawa Excel Discussion (Misc queries) 1 March 30th 09 05:17 PM
On opening Excel, 4 non ".xls" files open that I cannot delete Twoheat Excel Discussion (Misc queries) 2 March 6th 06 02:36 PM
creating an XLS file from " files" data in a Folder Edwin Mashiringwani Excel Discussion (Misc queries) 2 November 19th 05 04:45 PM
"Folder Select" Dialogue - Opening multiple files from selected folder Rob[_26_] Excel Programming 2 September 30th 05 02:47 PM


All times are GMT +1. The time now is 07:03 PM.

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"