返回列表 上一主題 發帖

[發問] EXCEL檔案內的儲存格內容如何寫VBA匯出成TXT檔案格式?

[發問] EXCEL檔案內的儲存格內容如何寫VBA匯出成TXT檔案格式?

小弟有一份EXCEL表格要轉成TXT格式 ,但是怎麼弄就是無法與TXT格式對齊
請求各位大大有甚麼方法. 謝謝
轉換成TXT格式並對齊.rar (13.05 KB)
小武

只有檔案, 沒有說明規則邏輯,
應該沒有能解~~

TOP




小武

TOP

不是TXT???
怎又是CSV???

TOP

回復 4# 准提部林

就是CSV的內容 轉成跟TXT一樣的對齊方式
小武

TOP

文字檔/excel檔/與圖片中的csv
內容都不相同, 難以聯想一起~~
辦不了~~

TOP

說不清楚, 只能猜一下:
Xl0000423.rar (16.38 KB)

TOP

本帖最後由 show5217 於 2019-7-23 10:20 編輯

回復 7# 准提部林


謝謝, 指教了. 我是用下面這種方法
new_id = s_id
        n = n + 1
        Sheet1.Cells(n, "n") = s_id
        txt_str = txt_str & Space(7 - Len(s_id)) & s_id
        
        If Sheet1.Cells(i, "f") <> "" Then
            Sheet1.Cells(n, "o") = Sheet1.Cells(i, "f")
            txt_str = txt_str & Space(1) & Sheet1.Cells(n, "o") & Space(21 - Len(Sheet1.Cells(n, "o")))
            j = j + 1
            txt_str = txt_str & Space(22)
            If Sheet1.Cells(i, "e") = "" Then
                Sheet1.Cells(n, "q") = "-"
            Else
                Sheet1.Cells(n, "q") = Sheet1.Cells(i, "e")
            End If
            txt_str = txt_str & Sheet1.Cells(n, "q") & Space(2)
            Set Rng = Sheet2.Range("a:a").Find(Sheet1.Cells(i, "g"), lookat:=xlWhole)
            If Not Rng Is Nothing Then
                r = Rng.Row
                supply = Sheet2.Cells(r, "b")
            Else
                supply = Sheet1.Cells(i, "g")
            End If
            Sheet1.Cells(n, "r") = supply
            txt_str = txt_str & supply & Space(40 - Len(supply))
            Sheet1.Cells(n, "s") = Sheet1.Cells(i, "h")
            txt_str = txt_str & Sheet1.Cells(n, "s") & Space(5 - Len(Sheet1.Cells(n, "s")))
        End If
        txt_str = txt_str & vbCrLf
小武

TOP

        靜思自在 : 靜坐常恩己過、閒談莫論人非。
返回列表 上一主題