Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default Visual Basic File selection

I've looked at related postings and have been unable to find the answer. Is
there a way to create a macro that would allow me to pull the same type of
data from different folders? In explaination; I am creating new filles in
which the data comes from existing files. What I am doing is opening the
existing file, copying the first sheet and then pasting it into the new file,
then going on to the next file. I'm sure there is an easier way to do this
but I just don't know how to go about solving the problem. Thank you.
Heath
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default Visual Basic File selection

Hi Heath

Try this example for all files in C:\Data
the new files will be saved in C:\

Be sure that the file with the code is not in C:\Data

Sub TestFile()
Dim mybook As Workbook
Dim sourceRange As Range
Dim destrange As Range
Dim FNames As String
Dim MyPath As String
Dim SaveDriveDir As String

SaveDriveDir = CurDir
MyPath = "C:\Data"
ChDrive MyPath
ChDir MyPath
FNames = Dir("*.xls")
If Len(FNames) = 0 Then
MsgBox "No files in the Directory"
ChDrive SaveDriveDir
ChDir SaveDriveDir
Exit Sub
End If

Application.ScreenUpdating = False
Do While FNames < ""
Set mybook = Workbooks.Open(FNames)
mybook.Worksheets(1).Copy
ActiveWorkbook.SaveAs "C:\copy of " & mybook.Name & _
Format(Now, "dd-mm-yy h-mm-ss")
ActiveWorkbook.Close False
mybook.Close False
FNames = Dir()
Loop
ChDrive SaveDriveDir
ChDir SaveDriveDir
Application.ScreenUpdating = True
End Sub


--
Regards Ron de Bruin
http://www.rondebruin.nl


"Heath" wrote in message ...
I've looked at related postings and have been unable to find the answer. Is
there a way to create a macro that would allow me to pull the same type of
data from different folders? In explaination; I am creating new filles in
which the data comes from existing files. What I am doing is opening the
existing file, copying the first sheet and then pasting it into the new file,
then going on to the next file. I'm sure there is an easier way to do this
but I just don't know how to go about solving the problem. Thank you.
Heath



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 to connect visual basic with excel file ? taha Excel Discussion (Misc queries) 2 October 26th 05 03:25 PM
creating an exe file with visual basic (installation file for Macros and Userforms) [email protected] Excel Programming 3 August 5th 04 10:16 AM
How to Open A File with Visual Basic Lance[_3_] Excel Programming 1 November 18th 03 08:43 PM
Excel-Microsoft Visual Basic File Not Found Donna McMahan Excel Programming 1 October 31st 03 05:02 PM
Converting text to pdf file using Visual Basic nitin khabia Excel Programming 1 September 12th 03 02:10 AM


All times are GMT +1. The time now is 02:43 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"