已爬過文--(網路上強人所寫的範例,拿來用)
--------------------------------------------------
Sub 匯入文字檔()
Dim MySht As Worksheet, uFile, ShtName, xSht As Worksheet, i&
Set MySht = Sheets("TEMP")
Application.ScreenUpdating = False
ShtName = Array("0", "430", "630", "1040", "1050", "2050", "3050")
'---------------------------------------
For i = 0 To UBound(ShtName)
uFile = ThisWorkbook.Path & "\" & ShtName(i) & ".txt"
If Dir(uFile) = "" Then GoTo NEXT_FILE
'----------------------------------------
For Each xSht In Sheets
If xSht.Name = ShtName(i) Then
Application.DisplayAlerts = False
xSht.Delete
Application.DisplayAlerts = True
End If
Next
Sheets.Add After:=Sheets(Sheets.Count)
ActiveSheet.Name = ShtName(i)
'-----------------------------------------
With ActiveSheet.QueryTables.Add(Connection:="TEXT;" & uFile, Destination:=Range("A1"))
.AdjustColumnWidth = False
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = True
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = False
.TextFileSpaceDelimiter = False
.TextFileColumnDataTypes = Array(1, 1, 1, 1, 1, 1, 1, 1)
.Refresh BackgroundQuery:=False
.Delete
End With
NEXT_FILE:
Next
'-------------------------------------------------------
MySht.Select
Application.ScreenUpdating = True
MsgBox "∼∼匯入完成∼∼ "
End Sub
--------------------------------------------------
Sub 匯入文字檔()
Dim MySht As Worksheet, uFile, ShtName, xSht As Worksheet, i&
Set MySht = Sheets("TEMP")
Application.ScreenUpdating = False
ShtName = Array("0", "430", "630", "1040", "1050", "2050", "3050")
'---------------------------------------
For i = 0 To UBound(ShtName)
uFile = ThisWorkbook.Path & "\" & ShtName(i) & ".txt"
If Dir(uFile) = "" Then GoTo NEXT_FILE
'----------------------------------------
For Each xSht In Sheets
If xSht.Name = ShtName(i) Then
Application.DisplayAlerts = False
xSht.Delete
Application.DisplayAlerts = True
End If
Next
Sheets.Add After:=Sheets(Sheets.Count)
ActiveSheet.Name = ShtName(i)
'-----------------------------------------
Sub avg()
For i = 1 To 10
Sheets("0").Cells(i + 2, 12).Formula = "=AVERAGE($E$" & i & ":$E$" & i + 2 & ")"
Next i
End Sub作者: wj1228.518 時間: 2013-10-15 10:40