Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > VBA / Office Integration > Excel > Open All Files in Directory


Reply
 
Thread Tools Display Modes
  #1  
Old 05-29-2003, 10:55 AM
Sunny Sunny is offline
Freshman
 
Join Date: May 2003
Location: Southern California
Posts: 29
Default Open All Files in Directory

How do I open all files in a particular directory and copy to them within a VBA macro? Sunny
Reply With Quote
  #2  
Old 05-29-2003, 02:00 PM
NateBrei's Avatar
NateBrei NateBrei is offline
Contributor
 
Join Date: Jul 2002
Location: Omaha, NE
Posts: 570
Default

I think you need to be more explicit in your description. Are you talking about opening Excel files & copying data into them, opening text files & copying data into them, or copying the files to some other location (folder)?

Nate
Reply With Quote
  #3  
Old 05-29-2003, 07:49 PM
Sunny Sunny is offline
Freshman
 
Join Date: May 2003
Location: Southern California
Posts: 29
Default

Quote:
Originally Posted by NateBrei
I think you need to be more explicit in your description. Are you talking about opening Excel files & copying data into them, opening text files & copying data into them, or copying the files to some other location (folder)?

Nate


I'd like to open all Excel files in a subdirectory because I'll be pasting data into these files from another Excel sheet in a different dir. The paste will occur in sheets named "Data" which is the same in all the destination files. I understand the copy and paste portion, I just don't know how to get the files opened up to cycle thru and copy to them.
Reply With Quote
  #4  
Old 05-30-2003, 05:45 AM
mwilding's Avatar
mwilding mwilding is offline
Junior Contributor
 
Join Date: May 2003
Location: Thunder Bay, Ontario
Posts: 281
Default

Sunny

This should get you going.

Mike

Sub Open_My_Files()
Dim MyFile As String
MyPath = "D:\Data\"
MyFile = Dir(MyPath)

Do While MyFile <> ""
If MyFile Like "*.xls" Then
Workbooks.Open MyPath & MyFile
Sheets(1).Select
'Paste Code here
ActiveWorkbook.Close True
End If
MyFile = Dir
Loop
End Sub
Reply With Quote
  #5  
Old 05-30-2003, 10:11 AM
Sunny Sunny is offline
Freshman
 
Join Date: May 2003
Location: Southern California
Posts: 29
Default

Quote:
Originally Posted by mwilding
Sunny

This should get you going.

Mike

Sub Open_My_Files()
Dim MyFile As String
MyPath = "D:\Data\"
MyFile = Dir(MyPath)

Do While MyFile <> ""
If MyFile Like "*.xls" Then
Workbooks.Open MyPath & MyFile
Sheets(1).Select
'Paste Code here
ActiveWorkbook.Close True
End If
MyFile = Dir
Loop
End Sub


Mike-
How can I get to be as smart as you?? You are the MAN!! Thanks so much. I spent 3 days trying to figure this one out and you got it!! Much appreciation...Sunny :-D
Reply With Quote
  #6  
Old 05-30-2003, 05:17 PM
mwilding's Avatar
mwilding mwilding is offline
Junior Contributor
 
Join Date: May 2003
Location: Thunder Bay, Ontario
Posts: 281
Default

Sunny

Practice (4 1/2 years), Frustration (Beat the computer), No one to really turn to (Did not know about this place)!

Mike
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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 Off
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Beginner help with timers. School program... KreeZiE General 18 04-24-2003 04:45 PM
Makin a nice little program! Decontain Communications 3 04-11-2003 02:54 AM
Searching for files in a directory Mark Fyffe General 1 04-09-2003 01:00 PM
Required files burningodzilla General 11 09-12-2001 04:51 PM

Advertisement:

Powered by liquidweb