- 帖子
- 2
- 主題
- 1
- 精華
- 0
- 積分
- 5
- 點名
- 0
- 作業系統
- xp
- 軟體版本
- office2000
- 閱讀權限
- 10
- 註冊時間
- 2014-11-13
- 最後登錄
- 2014-12-1
|
[發問] 將excel中的日期匯出成指定格式的txt檔案
請問我有2個excel檔案 想要匯出成 ansi 格式的txt檔
試了兩天都不能成功 因為在a欄的地方 是以"日期 時間"的格式存放
如: 2014/01/31 09:45:00 PM
我要輸出成 "2014/01/31 09:45"這樣的格式
我用錄巨集然後資料剖析把日期轉成文字 最後輸出的文字檔卻變成:
"1/31/2014 1:45:0"
不知是那裡出了錯? 另外輸出txt檔的時候 能不能只輸出當天的資料 昨天以前的不要?
以下是我的巨集:
Sub Macro2()
'
' 快速鍵: Ctrl+Shift+Q
'
Dim AA, BB, CC, DD, EE, FF, GG As String
Dim a As Integer
Workbooks.Open Filename:="C:\Documents and Settings\Administrator\桌面\1.csv"
Columns("B:B").Select
Selection.Insert Shift:=xlToRight
Columns("A:A").Select
Selection.TextToColumns Destination:=Range("A1"), DataType:=xlFixedWidth, _
FieldInfo:=Array(Array(0, 2), Array(17, 1))
Open "c:\txtmin5\tw100.txt" For Output As #1
For a = [a65536].End(xlUp).Row - 60 To [a65536].End(xlUp).Row
AA = Cells(a, 1)
BB = Cells(a, 3)
CC = Cells(a, 4)
DD = Cells(a, 5)
EE = Cells(a, 6)
FF = Cells(a, 7)
mystr = AA & " " & BB & " " & CC & " " & DD & " " & EE & " " & FF
Print #1, mystr
Next a
Close #1
ActiveWindow.Close
End Sub
附檔是未處理的檔案跟要輸出txt檔的目標格式
1.rar (6.52 KB)
麻煩大家了 謝謝 |
|