2
현재 작은 폴더에있는 xslx
개의 파일을 모두 탐색하여 모두 xml
개의 워크 시트로 저장할 수 있습니다. 잘 작동하지만 하위 폴더에 저장하고 싶습니다, 나는 항상 다시 같은 파일을 저장하고있어 같은 일이 잘못 곳이야하위 폴더에 * .xml 통합 문서를 저장할 때 Dir 문제가 발생했습니다.
. 나는 Dir
구문에 너무 익숙하지 않기 때문에 누군가가 나를 조금 도와 줄 수 있다면 정말 감사 할 것입니다.
이 부분은 예상대로 작동합니다
Sub XLS2XML()
Application.DisplayAlerts = False
Dim folderPath As String
Dim Report As String
Dim ReportName As String
Dim XMLLocation As String
Dim XMLReport As String
Dim WB As Workbook
'set path to current location
folderPath = ThisWorkbook.Path
If Right(folderPath, 1) <> "\" Then folderPath = folderPath + "\"
'loop through all xlsx files
Report = Dir(folderPath & "*.xlsx")
Do While Report <> ""
Set WB = Workbooks.Open(folderPath & Report)
'get the file name without path
ReportName = Split(Report, ".")(0)
XMLLocation = folderPath
XMLReport = XMLLocation & ReportName & ".xml"
'save the file as xml workbook
ActiveWorkbook.SaveAs filename:=XMLReport, _
FileFormat:=xlXMLSpreadsheet, ReadOnlyRecommended:=False, CreateBackup:=False
'close and next
WB.Close False
Report = Dir
Loop
MsgBox "All XML files have been created"
Application.DisplayAlerts = True
End Sub
이 하나 나에 실패
Sub XLS2XML()
Application.DisplayAlerts = False
Dim folderPath As String
Dim Report As String
Dim ReportName As String
Dim XMLLocation As String
Dim XMLReport As String
Dim WB As Workbook
'set path to current location
folderPath = ThisWorkbook.Path
If Right(folderPath, 1) <> "\" Then folderPath = folderPath + "\"
'loop through all xlsx files
Report = Dir(folderPath & "*.xlsx")
Do While Report <> ""
Set WB = Workbooks.Open(folderPath & Report)
'get the file name without path and save it in xml folder
ReportName = Split(Report, ".")(0)
XMLLocation = folderPath & "xml"
XMLReport = XMLLocation & "\" & ReportName & ".xml"
'create xml folder if it doesn't exist yet
If Len(Dir(XMLLocation, vbDirectory)) = 0 Then
MkDir XMLLocation
End If
'save the file as xml workbook
ActiveWorkbook.SaveAs filename:=XMLReport, _
FileFormat:=xlXMLSpreadsheet, ReadOnlyRecommended:=False, CreateBackup:=False
'close and next
WB.Close False
Report = Dir
Loop
내 구문이 잘못되면 어떤 생각? 또한 자동 모드에서 동일한 작업을 수행 할 수 있습니까? 그럼 통합 문서를 열지 않고?
감사합니다.