作者aup65797 (有缘人)
看板Office
标题[问题] VBA 读取txt档格式问题
时间Mon Mar 27 20:54:24 2017
(若是和其他不同软体互动之问题 请记得一并填写)
软体:Office
版本:2010
https://www.dropbox.com/s/hxsh00gkvz4xi2s/Log.txt?dl=0
以上为.txt档格式 , 以下为程式码不能读到正确的格式 ,
读到excel档sheet里会产生以下网址的格式
https://www.dropbox.com/s/0xgngpcmhg6ldwc/2017-03-27_205115.jpg?dl=0
Application.ScreenUpdating = False
Do
If xChk = 0 Then
xFile = Dir(ThisWorkbook.Path & "\*.txt")
If xFile = "" Then MsgBox "※找不到 TXT 档案! ", 0 + 16: Exit Sub
xChk = 1
Else
xFile = Dir
If xFile = "" Then Exit Do
End If
'----------------------------------------------
uFile = ThisWorkbook.Path & "\" & xFile
Set uHead = Range("A65536").End(xlUp)
uHead.Value = xFile
Set uHead = uHead(2, 1)
With ActiveSheet.QueryTables.Add(Connection:="TEXT;" & uFile, Destination:=uHead)
.AdjustColumnWidth = False
.TextFileParseType = xlDelimited
.TextFileTabDelimiter = True
.TextFileCommaDelimiter = True
.TextFileConsecutiveDelimiter = True
.Refresh
End With
Cells.Replace "", " "
uHead.Interior.ColorIndex = 6 '每笔第一格加〔黄色〕底
NEXT_LINE:
Loop
以下为读取到错误的格式
https://www.dropbox.com/s/mwcmcugwwpnmd6p/LOG_Picture.jpg?dl=0
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 123.241.96.6
※ 文章网址: https://webptt.com/cn.aspx?n=bbs/Office/M.1490619270.A.53D.html
※ 编辑: aup65797 (123.241.96.6), 03/27/2017 21:04:35
1F:→ soyoso: 加上textfilespacedelimiter和textfileotherdelimiter 03/27 21:14
3F:→ aup65797: 都改为True吗? 03/27 21:26
4F:→ aup65797: OK了 , 感谢S大 03/27 21:33