닉,
당신이 차이 귀하의 질문에 확장을 감안할 때, 그리고 지퍼 부분은 내가 그 아래의 솔루션 요약 한 중요한 부가 기능이다 : 특정 시트를 건너 뛰는,
- 는 CSV 파일을 작성을 이 라인 사용
Case "TOC", "Lookup"
- Zip 파일에 추가합니다. 이 섹션에서는
ActiveWorkbook
가 저장되는 코드의 테스트 파일을 이미 CSV로 서브 나누어 가져옵니다 ActiveWorkbook
으로 존재하지 않는 경우 코드는 StrMain
및 StrZipped
아래의 경로를 생성합니다 Ron de Bruin's code here
에 크게 그립니다 진행하기 전에
On (2) 내가 전에 Produce an Excel list of the attributes of all MP3 files that sit in or below the "My Music" folde에 봤던 문제를 건너 뛰었습니다. 여기서 문자열 변수가 전달되었을 때 Shell.Application
오류가 발생했습니다. 그래서 나는 내 이빨을 두들겨서 Zip_All_Files_in_Folder
에 대한 이전 경로의 하드 코딩을 추가했습니다.나는이
VBA to save CSVS
Public Sub SaveWorksheetsAsCsv()
Dim ws As Worksheet
Dim strMain As String
Dim strZipped As String
Dim strZipFile As String
Dim lngCalc As Long
strMain = "C:\csv\"
strZipped = "C:\zipcsv\"
strZipFile = "MyZip.zip"
If Not ActiveWorkbook.Saved Then
MsgBox "Pls save " & vbNewLine & ActiveWorkbook.Name & vbNewLine & "before running this code"
Exit Sub
End If
With Application
.DisplayAlerts = False
.ScreenUpdating = False
lngCalc = .Calculation
.Calculation = xlCalculationManual
End With
'make output diretcories if they don't exist
If Dir(strMain, vbDirectory) = vbNullString Then MkDir strMain
If Dir(strZipped, vbDirectory) = vbNullString Then MkDir strZipped
For Each ws In ActiveWorkbook.Worksheets
Select Case ws.Name
Case "TOC", "Lookup"
'do nothing for these sheets
Case Else
ws.SaveAs strMain & ws.Name, xlCSV
End Select
Next
'section to run the zipping
Call NewZip(strZipped & strZipFile)
Application.Wait (Now + TimeValue("0:00:01"))
Call Zip_All_Files_in_Folder '(strZipped & strZipFile, strMain)
'end of zipping section
With Application
.DisplayAlerts = True
.ScreenUpdating = True
.Calculation = lngCalc
End With
End Sub
'Create the ZIP file if it doesn't exist
Sub NewZip(sPath As String)
'Create empty Zip File
'Changed by keepITcool Dec-12-2005
If Len(Dir(sPath)) > 0 Then Kill sPath
Open sPath For Output As #1
Print #1, Chr$(80) & Chr$(75) & Chr$(5) & Chr$(6) & String(18, 0)
Close #1
End Sub
'Add the files to the Zip file
Sub Zip_All_Files_in_Folder() '(sPath As String, ByVal strMain)
Dim oApp As Object
Set oApp = CreateObject("Shell.Application")
'Shell doesn't handle the variable strings in my testing. So hardcode the same paths :(
sPath = "C:\zipcsv\MyZip.zip"
strMain = "c:\csv\"
'Copy the files to the compressed folder
oApp.Namespace(sPath).CopyHere oApp.Namespace(strMain).items
MsgBox "You find the zipfile here: " & sPath
End Sub
01을 시도 어디 보여 내 이전 변수 전달에서 주석
[매크로를 사용하여 각 시트를 Excel 통합 문서에 저장하여 CSV 파일을 구분할 수 있습니다.] (http://stackoverflow.com/questions/59075/macro-to-save-each-sheet-in-an-excel-workbook -to-separate-csv-files) – bernie
SO *에는 보너스 포인트 시스템이 있지만 사용하지는 않습니다. 사기꾼! – bzlm
비슷한 응답으로 제시된 해결책이 본인의 요구 사항을 해결하지 못합니다. 그 스레드에 게시해야한다면 사과드립니다. –