一区二区三区日韩精品-日韩经典一区二区三区-五月激情综合丁香婷婷-欧美精品中文字幕专区

分享

ACCESS通過VBA讀取TXT不亂碼(轉(zhuǎn)載)

 恐怖騎士 2012-07-20
ACCESS通過VBA讀取TXT不亂碼(轉(zhuǎn)載)
2010-07-06 07:43
昨天幫領(lǐng)導(dǎo)做了一個TOOLS,功能是把一個文件夾下的所有TXT文件,按照特定的方式讀取出來,進(jìn)行篩選,
由于我覺得篩選邏輯比較復(fù)雜,所以我采用了ACCESS的讀取方式,把TXT內(nèi)容讀取到數(shù)據(jù)庫中,然后通過SQL問進(jìn)行篩選。上來就遇到了問題ACCESSVBA讀取TXT讀進(jìn)去的都亂碼,嘗試了各種方式,都是如此,后來靈機(jī)一動放棄了文件的單純讀取,通過讀取EXCEL的方式讀取,居然成功了,分享一下給大家。
Option Compare Database

Private Sub 実行_Click()
'    Dim txtLine As String
'    Dim FileObj As Object
'    Dim TextObj As Object
'    Dim FilePath
'    Dim MyPath$, MyFile$
'    Dim fs, f
'Const ForReading = 1, ForWriting = 2, ForAppending = 8, TristateFalse = 0
'
'    Set fs = CreateObject("Scripting.FileSystemObject")
'    Set f = fs.OpenTextFile("D:\tools\result.txt", 8, True, TristateFalse)
'
'    FilePath = txtPATH.Value
'
'    MyPath = FilePath & "\*.*"
'    MyFile = Dir(MyPath)
'    Do
'        Debug.Print MyFile
'        If MyFile <> "" Then
'            Set FileObj = CreateObject("Scripting.FileSystemObject")
'            Set TextObj = FileObj.OpenTextFile(FilePath & "\" & MyFile, ForReading, TristateTrue)
'            Do While Not TextObj.AtEndOfLine
'                txtLine = Trim(TextObj.ReadLine)
'                'If InStr(txtLine, "タイプ作成中") > 0 Then
'                    f.writeline txtLine & vbCrLf
'                'End If
'            Loop
'        End If
'        MyFile = Dir
'    Loop Until MyFile = ""
'    f.Close

'--------------------------------------------------------------------------------------
'    Dim txtLine As String
'    Dim FileObj As Object
'    Dim TextObj As Object
'    Dim FilePath
'    Dim MyPath$, MyFile$
'    Dim fs, f
'Const ForReading = 1, ForWriting = 2, ForAppending = 8, TristateFalse = 0
'
'    Set fs = CreateObject("Scripting.FileSystemObject")
'    Set f = fs.OpenTextFile("D:\tools\result.txt", 8, True, TristateFalse)
'
'    FilePath = txtPATH.Value
'
'    MyPath = FilePath & "\*.*"
'    MyFile = Dir(MyPath)
'    Do
'        Debug.Print MyFile
'        If MyFile <> "" Then
'                Dim strRtn As String
'                Set stm = New ADODB.Stream
'                stm.Type = 2
'                stm.Mode = 3
'                stm.Charset = "UTF-8"
'                stm.Open
'                stm.LoadFromFile FilePath & "\" & MyFile
'                strRtn = stm.ReadText
'                stm.Close
'                Set stm = Nothing
'                ReadFromFileADO = strRtn
'        End If
'        MyFile = Dir
'    Loop Until MyFile = ""
'    f.Close
'-----------------------------------
'    Dim txtLine As String
'    Dim FileObj As Object
'    Dim TextObj As Object
'    Dim FilePath
'    Dim MyPath$, MyFile$
'    Dim fs, f
'Const ForReading = 1, ForWriting = 2, ForAppending = 8, TristateFalse = 0
'
'    Set fs = CreateObject("Scripting.FileSystemObject")
'    Set f = fs.OpenTextFile("D:\tools\result.txt", 8, True, TristateFalse)
'
'    FilePath = txtPATH.Value
'
'    MyPath = FilePath & "\*.*"
'    MyFile = Dir(MyPath)
'    Do
'        Debug.Print MyFile
'        If MyFile <> "" Then
'            Dim ff As String
'            Dim Txt() As String
'            Dim i As Integer
'            i = 0
'
'            ff = FilePath & "\" & MyFile
'            Open ff For Input As #1
'              Do Until EOF(1)
'                 Line Input #1, txtLine
'
'                 i = i + 1
'              Loop
'            Close #1
'        End If
'        MyFile = Dir
'    Loop Until MyFile = ""
Dim txtLine As String
Dim FileObj As Object
Dim TextObj As Object
Dim FilePath
Dim MyPath$, MyFile$
Dim fs, f
Dim EXEファイル名(1 To 10000) As String
Dim 機(jī)能(1 To 10000) As String
Dim PBL名(1 To 10000) As String
Dim Object名(1 To 10000) As String
Dim xlApp As Excel.Application
Dim xlBook As Excel.Workbook
Set xlApp = New Excel.Application
Dim sheet As Excel.Worksheet
Dim FLAG As Integer

Const ForReading = 1, ForWriting = 2, ForAppending = 8, TristateFalse = 0

Set fs = CreateObject("Scripting.FileSystemObject")
FLAG = 0
FilePath = txtPATH.Value

MyPath = FilePath & "\*.*"
MyFile = Dir(MyPath)
Do
Debug.Print MyFile
If MyFile <> "" Then

Set xlBook = xlApp.Workbooks.Open(FilePath & "\" & MyFile)
Set sheet = xlBook.Worksheets(1)

Dim ss As String
Dim a
For a = 1 To sheet.UsedRange.Rows.count - 1
ss = sheet.Cells(a, 1)
If InStr(ss, "タイプ作成中") > 0 Then
FLAG = 1
If InStr(ss, "pbl_exe_ver11a") = 0 Then
ss = Mid(ss, InStr(ss, "pbl_exe_ver11") + Len("pbl_exe_ver11") + 1)
Else
ss = Mid(ss, InStr(ss, "pbl_exe_ver11a") + Len("pbl_exe_ver11a") + 1)
End If
EXEファイル名(a) = Left(MyFile, InStr(MyFile, ".") - 1)

If InStr(ss, "\") = 0 Then
'                     機(jī)能(a) = "共通"
'                     PBL名(a) = Left(ss, InStr(ss, "(") - 1)
'                     Object名(a) = Left(Mid(ss, InStr(ss, "(") + 1), Len(Mid(ss, InStr(ss, "(") + 1)) - 7)
Else
機(jī)能(a) = Left(ss, InStr(ss, "\") - 1)
PBL名(a) = Left(Split(ss, "\")(1), InStr(Split(ss, "\")(1), "(") - 1)
Object名(a) = Left(Split(ss, "(")(1), InStr(Split(ss, "(")(1), ")") - 1)
DoCmd.SetWarnings False
DoCmd.RunSQL ("INSERT INTO Logtable(EXEファイル名,機(jī)能,PBL名,Object名) VALUES('" & EXEファイル名(a) & "','" & 機(jī)能(a) & "','" & PBL名(a) & "','" & Object名(a) & "')")
DoCmd.SetWarnings True
End If
ElseIf FLAG = 1 Then
FLAG = 0
Exit For
End If
Next a
End If
MyFile = Dir
Loop Until MyFile = ""
Set sheet = Nothing
xlBook.Close (True)
Set xlBook = Nothing
xlApp.Quit
Set xlApp = Nothing
MsgBox "Success"
AllDataのサブフォーム.Requery
'Dim i As Long
'i = Shell("cmd.exe /c taskkill /f /im excel.exe", vbNormalFocus)
'    Dim i As Long
'    Dim r As Long
'    Dim p As Long
'    i = Shell("notepad.exe", vbNormalFocus)
'    p = OpenProcess(SYNCHRONIZE, False, i)
'    r = WaitForSingleObject(p, INFINITE)
'    r = CloseHandle(p)
End Sub

    本站是提供個人知識管理的網(wǎng)絡(luò)存儲空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點。請注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點擊一鍵舉報。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評論

    發(fā)表

    請遵守用戶 評論公約

    類似文章 更多

    国产精品一区二区日韩新区| 欧美成人欧美一级乱黄| 中文字幕日韩精品人一妻| 国产99久久精品果冻传媒| 日韩一本不卡在线观看| 美女露小粉嫩91精品久久久| 国产欧美日韩精品一区二区| 中文字幕日韩欧美亚洲午夜| 欧美午夜国产在线观看| 一区二区三区18禁看| 国产亚洲不卡一区二区| 国内女人精品一区二区三区| 免费在线成人午夜视频| 免费播放一区二区三区四区| 丝袜视频日本成人午夜视频| 免费性欧美重口味黄色| 日韩中文字幕视频在线高清版| 特黄大片性高水多欧美一级| 欧美一区二区三区性视频 | 亚洲av首页免费在线观看| 亚洲清纯一区二区三区| 美女黄色三级深夜福利| 大屁股肥臀熟女一区二区视频| 欧美成人精品国产成人综合| 日本少妇中文字幕不卡视频| 国产午夜福利在线免费观看| 国产精品日本女优在线观看| 久久精品久久久精品久久| 男人和女人草逼免费视频| 亚洲欧洲精品一区二区三区| 国产一区二区三区免费福利| 国产日韩在线一二三区| 日本久久精品在线观看| 好吊日在线视频免费观看| 国产水滴盗摄一区二区| 性欧美唯美尤物另类视频 | 亚洲一区二区精品久久av| 久久综合狠狠综合久久综合| 日韩高清毛片免费观看| 国产又色又爽又黄又免费| 激情国产白嫩美女在线观看|