Originally Posted by
mancubus
for the first option:
[vba]
Sub Convert_Cols_From_XMLfiles_to_XLSXfiles()
Dim codeWB As Workbook, xmlWB As Workbook, tmpWB As Workbook
Dim codeWS As Worksheet, xmlWS As Worksheet, tmpWS As Worksheet
Dim ColNums As Range, cll As Range, Col2Copy As Range
Dim i As Long, j As Long, xmlLR As Long, tmpLR As Long, Calc As Long
Dim xmlPath As String, tmpPath As String, tmpFile As String
Dim arrFiles As Variant
With Application
.EnableEvents = False
.ScreenUpdating = False
.DisplayAlerts = False
Calc = .Calculation
.Calculation = xlCalculationManual
End With
xmlPath = "H:\ms_ofis\dennnn\dene sil\"
tmpPath = "H:\ms_ofis\dennnn\dene sil\ConvertedFromXmlToTmp\"
If Dir(tmpPath, vbDirectory) = "" Then
MkDir tmpPath 'create folder if not exists
Else
On Error Resume Next
Kill tmpPath & "*.*" 'delete all files, if any, in folder if exists
On Error GoTo 0
End If
Set codeWB = ThisWorkbook
Set codeWS = codeWB.Worksheets("coding")
Set ColNums = codeWS.Range("C2:C25")
On Error Resume Next
Set tmpWB = Workbooks("template.xlsx")
If tmpWB Is Nothing Then Set tmpWB = Workbooks.Open(xmlPath & "template.xlsx")
Set tmpWS = tmpWB.Worksheets("template")
tmpLR = tmpWS.Cells(Rows.Count, 1).End(xlUp).Row
If tmpLR = 1 Then tmpLR = 2
tmpWS.Range("A2:X" & tmpLR).ClearContents
tmpWB.Save
tmpWB.Close
arrFiles = Application.GetOpenFilename(FileFilter:="Excel files (*.xls*), *.xls*", MultiSelect:=True)
If UBound(arrFiles) = 0 Then
MsgBox "No files selected!", vbOKOnly + vbCritical
Exit Sub
End If
On Error GoTo 0
For j = LBound(arrFiles) To UBound(arrFiles)
Set tmpWB = Workbooks.Open(xmlPath & "template.xlsx")
Set tmpWS = tmpWB.Worksheets("template")
tmpLR = tmpWS.Cells(Rows.Count, 1).End(xlUp).Row
If tmpLR = 1 Then tmpLR = 2
Set xmlWB = Workbooks.Open(arrFiles(j))
Set xmlWS = xmlWB.Worksheets("xml data source")
xmlLR = xmlWS.Cells(Rows.Count, 1).End(xlUp).Row
If xmlLR = 1 Then GoTo NextFile
i = 1
For Each cll In ColNums
Set Col2Copy = Range(xmlWS.Cells(2, cll.Value), xmlWS.Cells(xmlLR, cll.Value))
Col2Copy.Copy tmpWS.Cells(2, i)
i = i + 1
Next
tmpWS.Range("Q2:Q" & tmpWS.Cells(Rows.Count, 1).End(xlUp).Row).Value = "London"
tmpFile = "tmp_" & j & "_" & xmlWB.Name
With tmpWB
.SaveAs tmpPath & tmpFile, FileFormat:=51
.Close False
End With
xmlWB.Close False
NextFile:
Next
With Application
.EnableEvents = True
.ScreenUpdating = True
.DisplayAlerts = True
.Calculation = Calc
End With
End Sub
[/vba]