Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 157
Default Opening excel files automatically

Hi,

I have a folder "C:\CCAPPS\ttlview\TMP" and I want to open all the excel
files in this automatically. ( there are around 20 to 25 files normally in
this folder)

Once opened I will be running macros which will be collating data from these
files and doing some further operations. (I learned those macros from the
help of Newsgroups only).

Please tell me if this is possible.

Regards,
Hari
India


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 227
Default Opening excel files automatically

Hi Hari

Sub OpenWorkbooksInLocation()
Application.ScreenUpdating = False
Dim i as integer
With Application.FileSearch
..NewSearch
..LookIn = "C:\CCAPPS\ttlview\TMP"
..SearchSubFolders = False
..FileName = "*.xls"
..Execute
For i = 1 To .FoundFiles.Count
Set wb = Workbooks.Open(FileName:=.FoundFiles(i))
'Macro code for each workbook here
wb.Save
wb.Close
Next i
End With
Application.ScreenUpdating = True
End Sub


--
XL2002
Regards

William



"Hari" wrote in message
...
| Hi,
|
| I have a folder "C:\CCAPPS\ttlview\TMP" and I want to open all the excel
| files in this automatically. ( there are around 20 to 25 files normally in
| this folder)
|
| Once opened I will be running macros which will be collating data from
these
| files and doing some further operations. (I learned those macros from the
| help of Newsgroups only).
|
| Please tell me if this is possible.
|
| Regards,
| Hari
| India
|
|


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 157
Default Opening excel files automatically

Hi William,

Thanx a lot for the code.

When I run it my excel hangs and even after waiting for 5 or 6 minutes there
is no result. I pressed Ctrl+break to get out of the code. Im using Excel
2002 and Win 2000.

When I enter the code after stopping it the line "For i = 1 To
..FoundFiles.Count" is highlighted in yellow.

Please tell me how to overcome the same.

Regards,
Hari
India


"William" wrote in message
...
Hi Hari

Sub OpenWorkbooksInLocation()
Application.ScreenUpdating = False
Dim i as integer
With Application.FileSearch
.NewSearch
.LookIn = "C:\CCAPPS\ttlview\TMP"
.SearchSubFolders = False
.FileName = "*.xls"
.Execute
For i = 1 To .FoundFiles.Count
Set wb = Workbooks.Open(FileName:=.FoundFiles(i))
'Macro code for each workbook here
wb.Save
wb.Close
Next i
End With
Application.ScreenUpdating = True
End Sub


--
XL2002
Regards

William



"Hari" wrote in message
...
| Hi,
|
| I have a folder "C:\CCAPPS\ttlview\TMP" and I want to open all the excel
| files in this automatically. ( there are around 20 to 25 files normally

in
| this folder)
|
| Once opened I will be running macros which will be collating data from
these
| files and doing some further operations. (I learned those macros from

the
| help of Newsgroups only).
|
| Please tell me if this is possible.
|
| Regards,
| Hari
| India
|
|




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 227
Default Opening excel files automatically

Hi Hari

Which line of the code does Excel hang on?

Are you sure theres is a folder called "C:\CCAPPS\ttlview\TMP"?

--
XL2002
Regards

William



"Hari" wrote in message
...
| Hi William,
|
| Thanx a lot for the code.
|
| When I run it my excel hangs and even after waiting for 5 or 6 minutes
there
| is no result. I pressed Ctrl+break to get out of the code. Im using Excel
| 2002 and Win 2000.
|
| When I enter the code after stopping it the line "For i = 1 To
| .FoundFiles.Count" is highlighted in yellow.
|
| Please tell me how to overcome the same.
|
| Regards,
| Hari
| India
|
|
| "William" wrote in message
| ...
| Hi Hari
|
| Sub OpenWorkbooksInLocation()
| Application.ScreenUpdating = False
| Dim i as integer
| With Application.FileSearch
| .NewSearch
| .LookIn = "C:\CCAPPS\ttlview\TMP"
| .SearchSubFolders = False
| .FileName = "*.xls"
| .Execute
| For i = 1 To .FoundFiles.Count
| Set wb = Workbooks.Open(FileName:=.FoundFiles(i))
| 'Macro code for each workbook here
| wb.Save
| wb.Close
| Next i
| End With
| Application.ScreenUpdating = True
| End Sub
|
|
| --
| XL2002
| Regards
|
| William
|
|

|
| "Hari" wrote in message
| ...
| | Hi,
| |
| | I have a folder "C:\CCAPPS\ttlview\TMP" and I want to open all the
excel
| | files in this automatically. ( there are around 20 to 25 files
normally
| in
| | this folder)
| |
| | Once opened I will be running macros which will be collating data from
| these
| | files and doing some further operations. (I learned those macros from
| the
| | help of Newsgroups only).
| |
| | Please tell me if this is possible.
| |
| | Regards,
| | Hari
| | India
| |
| |
|
|
|
|


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 157
Default Opening excel files automatically

Hi William,

In ur code excel hangs and when I press the desktop bar for excel it doesnt
respond even after 8 or 9 mintues ( Presently in that folder I have only 5
or so files but very soon I will have 20 or so files). Yes, the folder
exists because Im referencing this folder for some of my other macros and
they work perfectly.

I then pressed Ctrl + Break ( Its strange that I have to press Ctrl + Break
many times before the program displays the following message). I get a
message similar to program has been interrupted and has three or four
buttons -- debug, end and help ( Im writing from memory). I chose debug and
when I enter VB editor I see that the line "For i = 1 To .FoundFiles.Count"
is highlighted in yellow.

I then went to help ( Im very new to VB, just had a primer in C++ years
back) and typed filesearch and somehow made very slight modifications to
your orignal code which is given below and when I executed this it worked
fine.

If possible, please tell me why ur original code wasnt working. This would
help me in better understanding of VB

The lines I changes was to replace ur ".FileName = "*.xls"" with the
following line -- " .FileType = msoFileTypeExcelWorkbooks"

Though I dont know why the modified form works, I have one more doubt (
which I have posted in a new post and in a different subject about
"Displayalerts and screenupdating" ). The query is if I set
..SearchSubFolders = True, then one of the subfolders had a excel file of the
same name as in the root
folder. Inspite of this excel didnt display the message that 2 files with
same name cannot be opened. If possible, Please tell me why this was
happening.


Sub OpenWorkbooksInLocation()

Application.ScreenUpdating = False
Dim i As Integer
With Application.FileSearch
.NewSearch
.LookIn = "C:\CCAPPS\ttlview\TMP"
.SearchSubFolders = False
.FileType = msoFileTypeExcelWorkbooks
.Execute
For i = 1 To .FoundFiles.Count
Set wb = Workbooks.Open(filename:=.FoundFiles(i))
'Macro code for each workbook here
'wb.Save
'wb.Close
Next i
End With
Application.ScreenUpdating = True

End Sub


"William" wrote in message
...
Hi Hari

Which line of the code does Excel hang on?

Are you sure theres is a folder called "C:\CCAPPS\ttlview\TMP"?

--
XL2002
Regards

William



"Hari" wrote in message
...
| Hi William,
|
| Thanx a lot for the code.
|
| When I run it my excel hangs and even after waiting for 5 or 6 minutes
there
| is no result. I pressed Ctrl+break to get out of the code. Im using

Excel
| 2002 and Win 2000.
|
| When I enter the code after stopping it the line "For i = 1 To
| .FoundFiles.Count" is highlighted in yellow.
|
| Please tell me how to overcome the same.
|
| Regards,
| Hari
| India
|
|
| "William" wrote in message
| ...
| Hi Hari
|
| Sub OpenWorkbooksInLocation()
| Application.ScreenUpdating = False
| Dim i as integer
| With Application.FileSearch
| .NewSearch
| .LookIn = "C:\CCAPPS\ttlview\TMP"
| .SearchSubFolders = False
| .FileName = "*.xls"
| .Execute
| For i = 1 To .FoundFiles.Count
| Set wb = Workbooks.Open(FileName:=.FoundFiles(i))
| 'Macro code for each workbook here
| wb.Save
| wb.Close
| Next i
| End With
| Application.ScreenUpdating = True
| End Sub
|
|
| --
| XL2002
| Regards
|
| William
|
|

|
| "Hari" wrote in message
| ...
| | Hi,
| |
| | I have a folder "C:\CCAPPS\ttlview\TMP" and I want to open all the
excel
| | files in this automatically. ( there are around 20 to 25 files
normally
| in
| | this folder)
| |
| | Once opened I will be running macros which will be collating data

from
| these
| | files and doing some further operations. (I learned those macros

from
| the
| | help of Newsgroups only).
| |
| | Please tell me if this is possible.
| |
| | Regards,
| | Hari
| | India
| |
| |
|
|
|
|






  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 227
Default Opening excel files automatically

Hari

Perhaps the code failed on the line below because you changed "
..SearchSubFolders = False" to ".SearchSubFolders = True" and Excel attempted
to open 2 files with the same name - otherwise I cannot help further.
"For i = 1 To .FoundFiles.Count"

As a general rule its more efficient to open 1 file at a time, execute any
code, save and close the workbook and then go on to the next workbook. If
you do not follow this route and try and open a file with the same name as a
file that is already open you will run into problems.

I do not know why the line " .FileName = "*.xls" " didn't work - I assume
the files are all standard Excel (".xls") files.

Sorry I cannot help further - perhaps others following this post can.
--
XL2002
Regards

William



"Hari" wrote in message
...
| Hi William,
|
| In ur code excel hangs and when I press the desktop bar for excel it
doesnt
| respond even after 8 or 9 mintues ( Presently in that folder I have only 5
| or so files but very soon I will have 20 or so files). Yes, the folder
| exists because Im referencing this folder for some of my other macros and
| they work perfectly.
|
| I then pressed Ctrl + Break ( Its strange that I have to press Ctrl +
Break
| many times before the program displays the following message). I get a
| message similar to program has been interrupted and has three or four
| buttons -- debug, end and help ( Im writing from memory). I chose debug
and
| when I enter VB editor I see that the line "For i = 1 To
..FoundFiles.Count"
| is highlighted in yellow.
|
| I then went to help ( Im very new to VB, just had a primer in C++ years
| back) and typed filesearch and somehow made very slight modifications to
| your orignal code which is given below and when I executed this it worked
| fine.
|
| If possible, please tell me why ur original code wasnt working. This would
| help me in better understanding of VB
|
| The lines I changes was to replace ur ".FileName = "*.xls"" with the
| following line -- " .FileType = msoFileTypeExcelWorkbooks"
|
| Though I dont know why the modified form works, I have one more doubt (
| which I have posted in a new post and in a different subject about
| "Displayalerts and screenupdating" ). The query is if I set
| .SearchSubFolders = True, then one of the subfolders had a excel file of
the
| same name as in the root
| folder. Inspite of this excel didnt display the message that 2 files with
| same name cannot be opened. If possible, Please tell me why this was
| happening.
|
|
| Sub OpenWorkbooksInLocation()
|
| Application.ScreenUpdating = False
| Dim i As Integer
| With Application.FileSearch
| .NewSearch
| .LookIn = "C:\CCAPPS\ttlview\TMP"
| .SearchSubFolders = False
| .FileType = msoFileTypeExcelWorkbooks
| .Execute
| For i = 1 To .FoundFiles.Count
| Set wb = Workbooks.Open(filename:=.FoundFiles(i))
| 'Macro code for each workbook here
| 'wb.Save
| 'wb.Close
| Next i
| End With
| Application.ScreenUpdating = True
|
| End Sub
|
|
| "William" wrote in message
| ...
| Hi Hari
|
| Which line of the code does Excel hang on?
|
| Are you sure theres is a folder called "C:\CCAPPS\ttlview\TMP"?
|
| --
| XL2002
| Regards
|
| William
|
|

|
| "Hari" wrote in message
| ...
| | Hi William,
| |
| | Thanx a lot for the code.
| |
| | When I run it my excel hangs and even after waiting for 5 or 6 minutes
| there
| | is no result. I pressed Ctrl+break to get out of the code. Im using
| Excel
| | 2002 and Win 2000.
| |
| | When I enter the code after stopping it the line "For i = 1 To
| | .FoundFiles.Count" is highlighted in yellow.
| |
| | Please tell me how to overcome the same.
| |
| | Regards,
| | Hari
| | India
| |
| |
| | "William" wrote in message
| | ...
| | Hi Hari
| |
| | Sub OpenWorkbooksInLocation()
| | Application.ScreenUpdating = False
| | Dim i as integer
| | With Application.FileSearch
| | .NewSearch
| | .LookIn = "C:\CCAPPS\ttlview\TMP"
| | .SearchSubFolders = False
| | .FileName = "*.xls"
| | .Execute
| | For i = 1 To .FoundFiles.Count
| | Set wb = Workbooks.Open(FileName:=.FoundFiles(i))
| | 'Macro code for each workbook here
| | wb.Save
| | wb.Close
| | Next i
| | End With
| | Application.ScreenUpdating = True
| | End Sub
| |
| |
| | --
| | XL2002
| | Regards
| |
| | William
| |
| |

| |
| | "Hari" wrote in message
| | ...
| | | Hi,
| | |
| | | I have a folder "C:\CCAPPS\ttlview\TMP" and I want to open all the
| excel
| | | files in this automatically. ( there are around 20 to 25 files
| normally
| | in
| | | this folder)
| | |
| | | Once opened I will be running macros which will be collating data
| from
| | these
| | | files and doing some further operations. (I learned those macros
| from
| | the
| | | help of Newsgroups only).
| | |
| | | Please tell me if this is possible.
| | |
| | | Regards,
| | | Hari
| | | India
| | |
| | |
| |
| |
| |
| |
|
|
|
|


  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 157
Default Opening excel files automatically

Hi William,

Thanx a lot for all the help and support u provided me.

Im very very grateful to u.

Regards,
Hari
India



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
Excel opening another instance automatically DanF Excel Discussion (Misc queries) 0 July 9th 08 03:11 PM
show most recent files first when opening excel files Anne` Excel Discussion (Misc queries) 5 January 23rd 08 01:54 AM
Opening Quattro Pro for Windows files (*.WB1 Files) using Excel 20 PoundMutt Excel Discussion (Misc queries) 1 June 20th 07 03:50 AM
Automatically opening several Excel Files at startup SD Excel Discussion (Misc queries) 1 June 8th 05 05:32 PM
Automatically opening several Excel Files at startup Peo Sjoblom Excel Discussion (Misc queries) 0 June 8th 05 05:20 PM


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