2012-03-21 15 views
0

ファイル内の各ワークシートを.csvファイルにエクスポートするスクリプトが見つかりましたが、テキスト・タブ区切りファイルとしてシートをエクスポートするように調整する必要があります。私はそれを修正しようとしましたが、デリミタなしのテキストとしてエクスポートしています。ここでは、元のコードは次のとおりです。事前にこのエクスポート・マクロをテキスト・タブ区切り出力用に変更する必要があります

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 (e.g., 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 

感謝を:

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 (e.g., 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 

そして、ここでは、私はそれを変更した方法です!

答えて

2

Sepは、区切り文字のように見えますが、何も表示しないように見えます。 For Each..ループの前に次のコードを使用してください。

Sep = vbTab 

それとも

Sep = Chr(9) 
+0

ファンタスティック!完璧に動作します!ありがとうございました!! – user955289

関連する問題