PC Review


Reply
Thread Tools Rate Thread

How to browse folder and open xls file automatically in vba?

 
 
geniusideas
Guest
Posts: n/a
 
      21st Dec 2009
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



 
Reply With Quote
 
 
 
 
Bob Phillips
Guest
Posts: n/a
 
      21st Dec 2009
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" <(E-Mail Removed)> wrote in message
news:5d1037c2-72ae-4c87-a779-(E-Mail Removed)...
> 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
>
>
>



 
Reply With Quote
 
Ryan H
Guest
Posts: n/a
 
      21st Dec 2009
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" <(E-Mail Removed)> wrote in message
> news:5d1037c2-72ae-4c87-a779-(E-Mail Removed)...
> > 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
> >
> >
> >

>
>
> .
>

 
Reply With Quote
 
geniusideas
Guest
Posts: n/a
 
      21st Dec 2009
Sorry Bob,

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


 
Reply With Quote
 
Ryan H
Guest
Posts: n/a
 
      21st Dec 2009
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
>
>
> .
>

 
Reply With Quote
 
geniusideas
Guest
Posts: n/a
 
      21st Dec 2009
Yes, that exactly that I want..Just select folder then all file open
automatically
 
Reply With Quote
 
Bob Phillips
Guest
Posts: n/a
 
      23rd Dec 2009
My code does just that, as it is commented, you need to do something with
the opened workbook


---
HTH

Bob Phillips

"geniusideas" <(E-Mail Removed)> wrote in message
news:9eb404a0-4673-4395-af19-(E-Mail Removed)...
> Yes, that exactly that I want..Just select folder then all file open
> automatically



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Browse to a folder, not a file M Skabialka Microsoft Access 10 28th Jan 2009 03:23 AM
Browse and open the folder in asp.net Santel Microsoft ASP .NET 7 5th Mar 2008 01:50 AM
Browse, Open file, assign number on file, and print Ricky S. via AccessMonster.com Microsoft Access Form Coding 1 28th Nov 2005 09:35 PM
Automatically open "programs" file folder when OS starts cc Windows XP General 1 3rd May 2005 10:14 AM
How can I open an HTTP: folder and browse its contents? Jason Kendall Microsoft Dot NET 0 20th May 2004 01:35 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:08 PM.