Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 70
Default How to browse folder and open xls file automatically in vba?

Hi,
My Task now is to create excel macro that can:
1) User browse folder
2) Click folder--open then
3) Macro will automatically open all Excel file one by one
4) After open --- collect certain data
5) Close file

Anyone pls help for the VBA code.
Thanks



  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 834
Default How to browse folder and open xls file automatically in vba?

Sub Main()
Dim fd As FileDialog
Dim SelectedItem As Variant

Set fd = Application.FileDialog(msoFileDialogFilePicker)
With fd

.AllowMultiSelect = True
If .Show = -1 Then

For Each SelectedItem In .SelectedItems

Workbooks.Open (SelectedItem)
'do something with activeworkbook
Next SelectedItem
End If
End With

Set fd = Nothing

End Sub


---
HTH

Bob Phillips

"geniusideas" wrote in message
...
Hi,
My Task now is to create excel macro that can:
1) User browse folder
2) Click folder--open then
3) Macro will automatically open all Excel file one by one
4) After open --- collect certain data
5) Close file

Anyone pls help for the VBA code.
Thanks





  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 489
Default How to browse folder and open xls file automatically in vba?

Hey Bob, just out of curiosity. I have been programming with VBA for 2-3
years now and I see some people setting there object variables to Nothing at
the end of the code. What is the purpose of this? Doesn't Excel do that for
you once the procedure is done in most cases?
--
Cheers,
Ryan


"Bob Phillips" wrote:

Sub Main()
Dim fd As FileDialog
Dim SelectedItem As Variant

Set fd = Application.FileDialog(msoFileDialogFilePicker)
With fd

.AllowMultiSelect = True
If .Show = -1 Then

For Each SelectedItem In .SelectedItems

Workbooks.Open (SelectedItem)
'do something with activeworkbook
Next SelectedItem
End If
End With

Set fd = Nothing

End Sub


---
HTH

Bob Phillips

"geniusideas" wrote in message
...
Hi,
My Task now is to create excel macro that can:
1) User browse folder
2) Click folder--open then
3) Macro will automatically open all Excel file one by one
4) After open --- collect certain data
5) Close file

Anyone pls help for the VBA code.
Thanks





.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 70
Default How to browse folder and open xls file automatically in vba?

Sorry Bob,

I can browse the folder but unable to open file inside
automatically..Still need to select.Pls help again.Thanks


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 489
Default How to browse folder and open xls file automatically in vba?

Bobs code works fine. You select the workbooks you want to open in the
folder you browse to and his code opens them.

Are you wanting to just select a folder and have the code automatically open
all Excel files in that folder? Try to be more specific on your needs.


--
Cheers,
Ryan


"geniusideas" wrote:

Sorry Bob,

I can browse the folder but unable to open file inside
automatically..Still need to select.Pls help again.Thanks


.



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 70
Default How to browse folder and open xls file automatically in vba?

Yes, that exactly that I want..Just select folder then all file open
automatically
  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 834
Default How to browse folder and open xls file automatically in vba?

My code does just that, as it is commented, you need to do something with
the opened workbook


---
HTH

Bob Phillips

"geniusideas" wrote in message
...
Yes, that exactly that I want..Just select folder then all file open
automatically



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
Code to Insert File as Icon & Open Browse Dialog Box Joyce Excel Programming 5 October 6th 09 02:06 PM
File Open (via browse) and then run my recorded macro Kolz Excel Programming 1 June 24th 09 04:09 AM
Browse for file and set initial folder to search [email protected] Excel Programming 3 January 30th 06 08:34 PM
FIle Open/Browse on Macintosh TooTall Excel Programming 1 October 31st 05 06:23 PM
File Browse Function (Open dialog box for choosing file) b-123 Excel Programming 1 August 25th 05 10:06 PM


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