Write to different XML file in function of the value of the cell

  • 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:

    It does`t work because it writes the same items in all the files.

    Thank you in advance!

  • ...
    My actual macro would be something like this:

    Is it this, or something like it?
    Please post a workbook that has the code and a sample set of data so that we can step through the code.

  • Ok ... this looks something like the code you posted but you now have this line of code:

    MkDir ThisWorkbook.Path & "\NR_Scripts_" & Cuando & ""

    where I get the following value which will NOT make a folder.

    C:\Users\BPettis\Downloads\NR_Scripts_12/5/2017 8:33:40 PM

    When I removed the "Cuando" variable from the path and ran the code ... It ran just fine. You'll need to explain further where it isn't working for you.

  • Hi Barry

    That's not really a problem because I'm still thinking about the name that the folder should have. :tumble:

    My problem begins here (I removed the "Cuando" variable as it's not important right now):

    As you can see in the "ExternalGSMCell" Sheet the first column is the modifier. What I am trying to do is to print to different file in function of that modifier. If you run the macro you can see that the output files are the same, indifferently from which is the modifier.

    Thank you.

  • This looks like it won't work.

    strExt3g2gCreate = ThisWorkbook.Path & "ThisWorkbook.path & "

    yeah your modifier was either create, update, delete. The code you posted ... worked ... well I believe it did.

  • Maybe step through the code "F8" in the ide window ... and look at the values in each variable then you can decide on the next step of execution what it should do.

    But like I said ... I removed the "cuando" variable and your code worked for me.

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!