- ©«¤l
- 12
- ¥DÃD
- 0
- ºëµØ
- 0
- ¿n¤À
- 62
- ÂI¦W
- 0
- §@·~¨t²Î
- win10
- ³nÅ骩¥»
- office 365
- ¾\ŪÅv
- 20
- ©Ê§O
- ¤k
- µù¥U®É¶¡
- 2022-2-1
- ³Ì«áµn¿ý
- 2022-12-29
|
TXT¸ê®Æ½Æ»s¨ìCsvªºµ{¦¡½X¹ï¶Ü!- Option Explicit
- Dim WB As Workbook, Csv_File As String, Txt_File As String, Txt_Path As String, Csv_Path As String, Save_Path As String
- Sub Ex_Main()
- Dim Msg As Variant
- Àˬd¸ê®Æ§¨
- Application.ScreenUpdating = False
- Application.StatusBar = " µ{¦¡°õ¦æ¤¤...................."
- Csv_File = Dir(Csv_Path & "\*.csv")
- Msg = Csv_File
- Do While Csv_File <> ""
- Txt_File = Txt_Path & "\" & Split(Csv_File, ".")(0) & ".txt" 'קïcsv °ÆÀɦW ¬°txt
- If CreateObject("Scripting.FileSystemObject").FileExists(Txt_File) = False Then MsgBox "§ä¤£¨ì " & vbLf & Txt_File & vbLf & "Àˬd«á «·s°õ¦æµ{¦¡!": End
- Set WB = Workbooks.Open(Csv_Path & Csv_File)
- TXT½Æ»s¦ÜCSV
- Csv_File = Dir()
- Msg = Msg & vbLf & Csv_File
- Loop
- Application.StatusBar = False
- Application.ScreenUpdating = True
- Msg = Split(Msg, vbLf)
- MsgBox Join(Msg, vbLf) & "§¹¦¨TXT½Æ»s¦ÜCSV " & UBound(Msg) & " ÓÀÉ®×"
- End Sub
- Private Sub Àˬd¸ê®Æ§¨()
- Dim Msg As String
- Save_Path = ThisWorkbook.Path & "\Test\" 'TXT½Æ»s¦ÜCSV ¦sÀɪº¸ê®Æ§¨
- Csv_Path = ThisWorkbook.Path & "\csvÀÉ\" 'csvÀÉÀɪº¸ê®Æ§¨
- Txt_Path = ThisWorkbook.Path & "\TXTÀÉ\" 'TXTÀɪº¸ê®Æ§¨
- If Dir(Save_Path, vbDirectory) = "" Then
- If MsgBox("«Ø¥ß " & Save_Path & " ¸ê®Æ§¨", vbYesNo) = vbYes Then
- MkDir (Save_Path)
- End If
- End If
- If Dir(Csv_Path, vbDirectory) = "" Then Msg = "§ä¤£¨ì " & Csv_Path
- If Dir(Txt_Path, vbDirectory) = "" Then Msg = Msg & vbLf & "§ä¤£¨ì " & Txt_Path
- If Msg <> "" Then MsgBox Msg & vbLf & "Àˬd«á «·s°õ¦æµ{¦¡!": End
- End Sub
- Private Sub TXT½Æ»s¦ÜCSV()
- Dim Sh As Worksheet, Rng As Range
- Set Sh = Workbooks.Open(Txt_File).Sheets(1) '¶}±ÒTXTªºSheets(1)
- Set Rng = WB.Sheets(1).Range("a1").End(xlDown).Offset(1) 'TXT¸ê®Æ½Æ»s¨ìCsvªº«ü©w¦ì¸m
- If Rng.Row = Rows.Count Then Set Rng = WB.Sheets(1).Range("a1")
- '«ü©w¦ì¸mªºRow= Rows.Count **«ü©w¦ì¸m¦bÀɮש³³¡®É --AÄ椤¨S¦³¸ê®Æ
- With Sh.Range("A1") '¸ê®ÆåªRAÄæ -,,,-> Comma:=True
- .CurrentRegion.TextToColumns Destination:=Range("A1"), DataType:=xlDelimited, _
- TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, _
- Semicolon:=False, Comma:=True, Space:=False, Other:=False, FieldInfo _
- :=Array(Array(1, 1), Array(2, 1)), TrailingMinusNumbers:=True
- .CurrentRegion.Copy Rng '**TXT¸ê®Æ½Æ»s¨ìCsv
- End With
- Sh.Parent.Close False 'Sh(Worksheet).Parent(¤÷¼h-Workbook)Ãö³¬
- If CreateObject("Scripting.FileSystemObject").FileExists(Save_Path & Csv_File) Then Kill Save_Path & Csv_File
- '**CreateObject("Scripting.FileSystemObject").FileExists=True **ªíÀɮצs¦b,¬G°õ¦æ Kill
- With WB
- .SaveAs Save_Path & Csv_File '-Workbook¥t¦s\Test\ ªº CsvÀÉ
- '**** FileExists=True ** .SaveAs ·|´£¥Ü¬O§_¨ú¥NìÀÉ®×-- µ{¦¡¼È®É¤¤Â_°õ¦æ
- .Close True
- End With
- End Sub
½Æ»s¥N½X ¦^´_ 3# èªÎ¯Ì¦Ï |
|