Hi all,
I have a macro that I use for work and I create XML files from the data in the Excel file. The first column of the worksheet is named "modifier" and the value in this column may be "create" "delete" or "modify". I am currently writing in the same file indifferently from which is the modifier. What I want to do is create three different files and write them in function of the modifier. So if the modifier is "create" write to Create.xml, if the modifier is "delete" write to Delete.xml and if the modifier is "modify" write to Modify.xml.
My actual macro would be something like this:
Code
Sub roponcio()
Dim SpecAtt AsString
SpecAtt= ThisWorkbook.Sheets("Sheet1").Cells(2, 1)
On Error Resume Next
MkDir ThisWorkbook.path&"\NR_Scripts"
On Error GoTo 0
Const oRange AsString="B2:B5000"
Dim oCell Asrange
ForEach oCell In range(oRange)
If oCell.Value="create" Then
Sheets("Sheet1").Select
strExtCreate= ThisWorkbook.Path&"ThisWorkbook.path & "\NR_Scripts"\Create_S.xml"
f= FreeFile
i=4
Open strExtCreate For Output As #f
While ThisWorkbook.Sheets("Sheet1").Cells(i, 2) <>""
Print #f, " <gn1 id="""&Cells(i, 2).Value&""" modifier=""create"">"
Print #f, " <gn3>"&Cells(i, 2).Value&"</gn3>"
Print #f, " <gn4>"&Cells(i, 3).Value&"</gn4>"
i= i+1
Wend
Close f
Else
If oCell.Value="update" Then
strExtUpdate= ThisWorkbook.Path&"ThisWorkbook.path & "\NR_Scripts"\Update_S.xml"
Sheets("Sheet1").Select
f= FreeFile
i=4
Open strExtUpdate For Output As #f
While ThisWorkbook.Sheets("Sheet1").Cells(i, 2) <>""
Print #f, " <gn1 id="""&Cells(i, 2).Value&""" modifier=""create"">"
Print #f, " <gn3>"&Cells(i, 2).Value&"</gn3>"
Print #f, " <gn4>"&Cells(i, 3).Value&"</gn4>"
i= i+1
Wend
Close f
End If
Next
End Sub
Display More
It does`t work because it writes the same items in all the files.
Thank you in advance!