2012-03-21 2 views
0

여기에 파일의 각 워크 시트를 .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 (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 

: 그리고 여기에 원래 코드는 사전에

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 

감사합니다!

답변

2

Sep은 구분 기호 여야하는 것처럼 보이지만 보이지 않는 것처럼 보입니다. For Each.. 루프 전에 다음을 사용하십시오.

Sep = vbTab 

또는

Sep = Chr(9) 
+0

환상적인! 완벽하게 작동합니다! 고맙습니다!! – user955289

관련 문제