標題:
[發問]
請教,如何逐一開啟子資料夾內之文字檔至EXCEL
[打印本頁]
作者:
cmo140497
時間:
2013-1-9 14:45
標題:
請教,如何逐一開啟子資料夾內之文字檔至EXCEL
Dear 各位大大 :
可否請各位幫忙看一下,MYFNAME已找到子資料夾之文字檔,但卻開不起來無法逐一輸入,謝謝!
Public dic
Sub ListFi()
Dim mypath As String
Dim theSh As Object, E As Object, theFolder As Object
Dim i As Integer
'Application.ScreenUpdating = False
On Error Resume Next
Set theSh = CreateObject("shell.application")
Set theFolder = theSh.BrowseForFolder(0, "", 0, "")
If Not theFolder Is Nothing Then
mypath = theFolder.Items.Item.Path
'MsgBox mypath
End If
With CreateObject("Scripting.FileSystemObject").GetFolder(mypath)
i = 1
For Each E In .SubFolders
If i > ActiveWorkbook.Sheets.Count Then
Sheets.Add(, Sheets(Sheets.Count)).Name = E.Name
Else
Sheets(i).Name = E.Name
End If
'--------------------------------------------
Dim MyTEXT As String, MYFNAME As String, WAFERID As String, ROWDATA_START As String
Dim EE As Integer, FILENO As Integer
'fs = Dir(fd & "*.txt")
EE = 4
On Error Resume Next
FILENO = FreeFile
MsgBox E.Name
fd = E & "\"
MYFNAME = Dir(fd & "*.txt")
'MYFNAME = Dir(E & "\", MacID("TEXT"))
If MYFNAME = "False" Then Exit Sub
Open MYFNAME For Input As #FILENO
WAFERID = "WAFER:"
ROWDATA_START = "RowData:"
'DEVICE = "DEVICE:"
'LOT = "LOT:"
'COLCT = "COLCT:"
Do While Not EOF(1)
Input #FILENO, MyTEXT
'If Mytxt Like DEVICE & "*" Then
'Cells(1, 1).Value = MyTEXT
'End If
'If Mytxt Like LOT & "*" Then
'Cells(2, 1).Value = MyTEXT
'End If
If Mytxt Like WAFERID & "*" Then
Cells(3, 1).Value = MyTEXT
End If
'If MYTXT Like COLCT & "*" Then
'Cells(4, 1).Value = MYTXT
'End If
If Mytxt Like ROWDATA_START & "*" Then
Cells(EE + 1, 1).Value = MyTEXT
EE = EE + 1
End If
Loop
Close #FILENO
'----------------------------------------------------------
ii = 12
For Each P In E.Files
'------------------------------------------
If InStr(UCase(P.Name), ".JPG") Then
ActiveWindow.Zoom = 70
Worksheets(i).Activate
'--設定圖片欄位大小
With Sheets(i).Cells(ii, 2).Select
With Selection
.RowHeight = 82
.ColumnWidth = 17
.WrapText = True
End With
'--設定圖片位置及長寬
t = Cells(ii, 2).Top + Cells(ii, 2).Height * 0.04 '圖片上位置
L = Cells(ii, 2).Left + Cells(ii, 2).Width * 0.04 '圖片左位置
w = 75 '圖片縮小75%寬度
h = 75 '圖片縮小75%高度
'--開始插入圖片
With Sheets(i).Shapes.AddPicture(P, True, True, L, t, w, h)
.Placement = xlMove
With Sheets(i)
.Cells(ii, 1) = P.Name '圖片檔案名稱
'.Cells(ii, 1) = P '圖片檔案完整路徑
End With
End With
End With
ii = ii + 1 '一次跳的欄位數
End If '--get .jpg file
Next
i = i + 1
Next
End With
'Sheets.Add After:=Sheets(Sheets.Count)
End Sub
Sub nn()
With ActiveSheet.Shapes(Application.Caller)
If .Left = ActiveSheet.[A1].Left Then
.Top = dic(.Name)(0)
.Left = dic(.Name)(1)
.Height = dic(.Name)(2)
.Width = dic(.Name)(3)
Else
.Height = dic(.Name)(2) * 3
.Width = dic(.Name)(3) * 3
.Top = ActiveSheet.[A1].Top
.Left = ActiveSheet.[A1].Left
'.ZOrder msoBringToFront
End If
End With
End Sub
複製代碼
[attach]13856[/attach]
作者:
cmo140497
時間:
2013-1-9 15:00
回復
1#
cmo140497
歹勢,小弟找到了,應在Open
fd & MYFNAME
For Input As #FILENO
歡迎光臨 麻辣家族討論版版 (http://forum.twbts.com/)