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


I am trying to build code. I am just a beginner with VBA. I am trying to
incorporate a colon delimiting option into this code when it brings in
all files. Also, I am trying to code a "save as" statement into the
code at the end. How do I go about this ?

Sub Import()
Dim MyPath As String
Dim FilesInPath As String
Dim MyFiles() As String
Dim SourceRcount As Long
Dim Fnum As Long
Dim mybook As Workbook
Dim basebook As Workbook


'Fill in the path\folder where the files are
'on your machine
MyPath = "c:\Data"


'Add a slash at the end if the user forget it
If Right(MyPath, 1) < "\" Then
MyPath = MyPath & "\"
End If


'If there are no Excel files in the folder exit the sub
FilesInPath = Dir(MyPath & "*.asc")
If FilesInPath = "" Then
MsgBox "No files found"
Exit Sub
End If


On Error GoTo CleanUp


Application.ScreenUpdating = False
Set basebook = ThisWorkbook


'Fill the array(myFiles)with the list of Excel files in the folder
Fnum = 0
Do While FilesInPath < ""
Fnum = Fnum + 1
ReDim Preserve MyFiles(1 To Fnum)
MyFiles(Fnum) = FilesInPath
FilesInPath = Dir()
Loop


'Loop through all files in the array(myFiles)
If Fnum 0 Then
For Fnum = LBound(MyFiles) To UBound(MyFiles)
Set mybook = Workbooks.Open(MyPath & MyFiles(Fnum))
mybook.Worksheets(1).Copy after:= _

basebook.Sheets(basebook.Sheets.Count)


On Error Resume Next
ActiveSheet.Name = mybook.Name
On Error GoTo 0


' You can use this if you want to copy only the values
' With ActiveSheet.UsedRange
' .Value = .Value
' End With


mybook.Close savechanges:=False
Next Fnum
End If
CleanUp:
Application.ScreenUpdating = True
End Sub


--
schnett
------------------------------------------------------------------------
schnett's Profile: http://www.excelforum.com/member.php...o&userid=12035
View this thread: http://www.excelforum.com/showthread...hreadid=543771

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
Importing multiple files Tommy Excel Discussion (Misc queries) 1 February 19th 07 03:00 PM
Importing multiple files Joel Excel Discussion (Misc queries) 0 February 19th 07 11:46 AM
importing multiple .dat files! via135 Excel Worksheet Functions 0 March 29th 06 08:09 PM
Importing from multiple text files tmort[_15_] Excel Programming 1 November 8th 05 01:42 PM
Importing Multiple files nearly there ianripping[_16_] Excel Programming 1 January 16th 04 01:01 AM


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