標題:
[發問]
請教版主,如何在Excel工作表上輸出為txt檔後,於欄位上增加冒號?
[打印本頁]
作者:
cmo140497
時間:
2013-11-1 14:52
標題:
請教版主,如何在Excel工作表上輸出為txt檔後,於欄位上增加冒號?
Dear 版主及各位大大們您好 :
小弟有一問題,在工作表內容輸出為文字檔後,想在A欄之文字後均加冒號,其餘皆依造原程式設定,不知該如何修正程式,請各位先進及版主不吝指正,感恩!
[attach]16538[/attach]
Sub TextExport()
Dim rng As Range
Dim iWks As Integer, iRow As Long, iCol As Integer
Dim sTxt As String, sPath As String
Dim ff As Integer
ff = FreeFile
sPath = ThisWorkbook.Path & "\"
For iWks = 2 To Worksheets.Count
Open sPath & Worksheets(iWks).Name & ".txt" For Output As #ff
Set rng = Worksheets(iWks).UsedRange
For iRow = 2 To rng.Rows.Count + 1
For iCol = 1 To rng.Columns.Count
If sTxt = "___" Then
sTxt = sTxt & " "
Else
sTxt = sTxt & Format(Worksheets(iWks).Cells(iRow, iCol).Value, "000") & " "
End If
Next iCol
Print #ff, sTxt
sTxt = vbNullString
Next iRow
Close #ff
Next iWks
End Sub
複製代碼
[attach]16539[/attach]
作者:
stillfish00
時間:
2013-11-1 15:46
回復
1#
cmo140497
16行
sTxt = sTxt & Format(Worksheets(iWks).Cells(iRow, iCol).Value, "000") & IIf(iCol = 1, ":", " ")
複製代碼
作者:
genes
時間:
2013-11-4 01:48
用replace不行嗎? copy空白位置, 貼下在搜尋, 冒號就是replace空白位置
歡迎光臨 麻辣家族討論版版 (http://forum.twbts.com/)