2017-03-29 69 views
0

我試圖自動化一個文件夾中有50個tsv文件的位置。他們必須通過記事本+ +打開並將其保存爲.txt文件在同一個文件夾中。通過Notepad ++打開tsv文件並將其保存爲文本格式

使用下面的代碼,我打開記事本++中的tsv文件。

MyTxtFile = Shell("C:\Program Files (x86)\Notepad++\notepad++.exe I:\Test\Sample.tsv", 1) 

但是,我不知道如何使用VBA將其保存爲txt文件。它可行嗎?如果是的話,請教我如何。

預先感謝您:)

+0

VBA並不意味着用作其他程序的自動化。爲什麼不使用大容量文件重命名器(例如[Ant Renamer](http://portableapps.com/apps/utilities/ant_renamer_portable))將tsv文件重命名爲txt文件? –

+0

另存爲csv文件'FileFormat:= xlCSV' – 0m3r

+0

@Peh如果我直接重命名它有一些影響數據的bug形成。因此,我們必須在Notepadd ++中打開。 – Linga

回答

1

終於找到了補救由通過數據導出=>從文本選項上面的問題可以得到解決..

下面是相同的代碼..

Do While fname <> "" 
Workbooks.Add 
Set wBook = ActiveWorkbook 
Set wksht = ActiveSheet 
    With wksht.QueryTables.Add(Connection:="TEXT;" & folder_name & fname, Destination:=Range("$A$1")) 
    .Name = fname 
    .FieldNames = True 
    .RowNumbers = False 
    .FillAdjacentFormulas = False 
    .PreserveFormatting = True 
    .RefreshOnFileOpen = False 
    .RefreshStyle = xlInsertDeleteCells 
    .SavePassword = False 
    .SaveData = True 
    .AdjustColumnWidth = True 
    .RefreshPeriod = 0 
    .TextFilePromptOnRefresh = False 
    .TextFilePlatform = 65001 
    .TextFileStartRow = 1 
    .TextFileParseType = xlDelimited 
    .TextFileTextQualifier = xlTextQualifierNone 
    .TextFileConsecutiveDelimiter = False 
    .TextFileTabDelimiter = True 
    .TextFileSemicolonDelimiter = False 
    .TextFileCommaDelimiter = False 
    .TextFileSpaceDelimiter = False 
    .TextFileColumnDataTypes = Array(1, 1, 1, 1, 1, 1, 1, 1, 1) 
    .TextFileTrailingMinusNumbers = True 
    .Refresh BackgroundQuery:=False 
End With 
1

如果只想將文件從* .tsv格式重命名爲* .TXT,你可以使用命令行

ren *.tsv *.txt 
+0

對不起FLex它不是隻爲重命名文件:( – Linga

相關問題