需要修改此导出macros的文本制表符分隔的输出

我在这里find了一个脚本,将每个工作表导出到一个.csv文件,但是我需要调整它来导出表单作为文本制表符分隔的文件。 我试图修改它,但它只是作为文本输出没有分隔符。 这是原始代码:

Public Sub DoTheExport() Dim FName As Variant Dim Sep As String Dim wsSheet As Worksheet Dim nFileNum As Integer Dim csvPath As String Sep = InputBox("Enter a single delimiter character (eg, comma or semi-colon)", _ "Export To Text File") 'csvPath = InputBox("Enter the full path to export CSV files to: ") csvPath = GetFolderName("Choose the folder to export CSV files to:") If csvPath = "" Then MsgBox ("You didn't choose an export directory. Nothing will be exported.") Exit Sub End If For Each wsSheet In Worksheets wsSheet.Activate nFileNum = FreeFile Open csvPath & "\" & _ wsSheet.Name & ".csv" For Output As #nFileNum ExportToTextFile CStr(nFileNum), Sep, False Close nFileNum Next wsSheet End Sub 

这里是我如何修改它:

 Public Sub DoTheExport() Dim FName As Variant Dim Sep As String Dim wsSheet As Worksheet Dim nFileNum As Integer Dim txtPath As String 'Sep = InputBox("Enter a single delimiter character (eg, comma or semi-colon)", _ '"Export To Text File") 'csvPath = InputBox("Enter the full path to export CSV files to: ") txtPath = GetFolderName("Choose the folder to export TXT files to:") If txtPath = "" Then MsgBox ("You didn't choose an export directory. Nothing will be exported.") Exit Sub End If For Each wsSheet In Worksheets wsSheet.Activate nFileNum = FreeFile Open txtPath & "\" & _ wsSheet.Name & ".txt" For Output As #nFileNum ExportToTextFile CStr(nFileNum), Sep, False Close nFileNum Next wsSheet End Sub 

提前致谢!

看起来好像你没有把Sep设置成任何东西,而是看起来应该是你的分隔符。 在For Each..循环之前使用以下内容。

 Sep = vbTab 

要么

 Sep = Chr(9)