I try and try, but nothing really happens. I have a Excel2000 Dutch version.
Any solutions??
Adri
Tom Ogilvy wrote:
| I recreated the environment you describe and ran the code. It ran
| fine for me.
|
|
| || Bob, the last version does not work either.
||
|| Bob Phillips wrote:
||| Adri,
|||
||| The line after Dim FSO is just for readability, it does nolthing and
||| affects nothing. I wonder if it is just wrap-around.
|||
||| Try this version
|||
||| Dim FSO As Object
|||
||| Sub ProcessFiles()
||| Dim i As Long
||| Dim sFolder As String
||| Dim fldr As Object
||| Dim Folder As Object
||| Dim file As Object
||| Dim Files As Object
||| Dim this As Workbook
||| Dim cnt As Long
|||
||| Set FSO = CreateObject("Scripting.FileSystemObject")
|||
||| Set this = ActiveWorkbook
||| sFolder = "C:\MyTest"
||| If sFolder <> "" Then
||| Set Folder = FSO.GetFolder(sFolder)
|||
||| Set Files = Folder.Files
||| cnt = 1
||| For Each file In Files
||| If file.Type = "Microsoft Excel Worksheet" Then
||| Workbooks.Open Filename:=file.Path
||| this.Worksheets.Add.Name = "File" & cnt
||| With ActiveWorkbook
||| .Worksheets(1).Range("A1:C100").Copy _
||| Destination:=this.Worksheets("File" & cnt).Range("A1")
||| .Close
||| End With
||| cnt = cnt + 1
||| End If
||| Next file
|||
||| End If ' sFolder <> ""
|||
||| End Sub
|||
|||
|||
||| |||| Bob Phillips wrote:
||||| Presumably you have modified the code? What does it look like now?
||||| And what Excel version do you have?
||||
|||| Hi Bob, code in module 1 of c:\text.xls is (didn't modify it)
|||| I'm working with Excel2000.
|||| After Dim FSO as Object follws a line, is that correct?
||||
|||| Option Explicit
||||
|||| Dim FSO As Object
||||
|||| Sub ProcessFiles()
|||| Dim i As Long
|||| Dim sFolder As String
|||| Dim fldr As Object
|||| Dim Folder As Object
|||| Dim file As Object
|||| Dim Files As Object
|||| Dim this As Workbook
|||| Dim cnt As Long
||||
|||| Set FSO = CreateObject("Scripting.FileSystemObject")
||||
|||| Set this = ActiveWorkbook
|||| sFolder = "C:\MyTest"
|||| If sFolder <> "" Then
|||| Set Folder = FSO.GetFolder(sFolder)
||||
|||| Set Files = Folder.Files
|||| cnt = 1
|||| For Each file In Files
|||| If file.Type = "Microsoft Excel Worksheet" Then
|||| Workbooks.Open Filename:=file.Path
|||| this.Worksheets.Add.Name = "File" & cnt
|||| With ActiveWorkbook
|||| .Worksheets(1).Range("A1:C100").Copy
|||| Destination:=this.Worksheets("File" & cnt).Range("A1")
|||| .Close
|||| End With
|||| cnt = cnt + 1
|||| End If
|||| Next file
||||
|||| End If ' sFolder <> ""
||||
|||| End Sub