附一
Sub yy()
Dim a As Workbook, f$, fn$, k%
Dim p$, Sh As Worksheet
Set a = ThisWorkbook
p = "C:\AAA\"
f = Dir(p & "*.CSV")
Application.ScreenUpdating = False
Do While f <> ""
Workbooks.Open p & f
k = 0
For Each Sh In Worksheets
If Not IsEmpty(Sh.UsedRange) Then
fn = IIf(k = 0, Replace(f, ".xls", ""), Replace(f, ".xls", "_") & k)
Sh.Copy after:=a.Sheets(a.Sheets.Count)
ActiveSheet.Name = fn
k = k + 1
End If
Next
Windows(f).Close True
f = Dir
Loop
Application.ScreenUpdating = True
End Sub作者: GBKEE 時間: 2014-9-12 16:48
表一
Sub yy()
Dim a As Workbook, f$, fn$, k%
Dim p$, Sh As Worksheet
Set a = ThisWorkbook
p = "C:\AAA\"
f = Dir(p & "*.CSV")
Application.ScreenUpdating = False
Do While f <> ""
Workbooks.Open p & f
k = 0
For Each Sh In Worksheets
If Not IsEmpty(Sh.UsedRange) Then
fn = IIf(k = 0, Replace(f, ".xls", ""), Replace(f, ".xls", "_") & k)
Sh.Copy after:=a.Sheets(a.Sheets.Count)
ActiveSheet.Name = fn
k = k + 1
End If
Next
Windows(f).Close True
f = Dir
Loop
Application.ScreenUpdating = True
Sheet14.Select
Range("A1").Select
End Sub作者: GBKEE 時間: 2014-9-16 16:19
'09. With Workbooks.Open(p & f).Sheets(1) 'CSV 只能有一張工作表
a_Sh.Name = Sh.Name '改看看
k = k + 1
End If
Next
.Close True
End With
f = Dir
Loop
Application.ScreenUpdating = True
Sheet14.Select
Range("A1").Select
End Sub
複製代碼
作者: rouber590324 時間: 2014-9-17 16:37
Dear sir -
依您之指導.修改如下 已可正常使用.感謝您 robert 09/18
Sub yy()
Dim a As Workbook, f$, fn$, k%
Dim p$, Sh, a_Sh As Worksheet
Set a = ThisWorkbook
p = "C:\AAA\"
f = Dir(p & "*.CSV")
Application.ScreenUpdating = False
Do While f <> ""
Workbooks.Open p & f
k = 0
For Each Sh In Worksheets
If Not IsEmpty(Sh.UsedRange) Then
fn = IIf(k = 0, Replace(f, ".xls", ""), Replace(f, ".xls", "_") & k)
Sh.Range("A1:Z500").Select
Set a_Sh = a.Sheets.Add '新增一工作表
a_Sh.Name = fn
Sh.UsedRange.Copy a_Sh.[a1] '複製已使用的範圍
ActiveSheet.Name = fn
k = k + 1
End If
Next
Windows(f).Close True
f = Dir
Loop
Application.ScreenUpdating = True