+ Reply to Thread
Results 1 to 44 of 44

Add date file via vba

  1. #1
    Forum Contributor
    Join Date
    07-14-2019
    Location
    Dubai
    MS-Off Ver
    2019
    Posts
    919

    Add date file via vba

    Hey

    I have xml table with headings
    I want vba button that allow me to select xml file from my pc, then add values into my table based on my settings..

    uploaded excel has original Table sheet and settings table sheet
    I want if I click import, system allow me to select xml file
    then macro read the file I choose, and see my setting table
    and paste only values of all equals data as I wrote in settings table, in the original table
    paste only values without changing anything or format

    I mention two heading in settings sheet, after I get the macro code I will add my others settings, it will be same idea.. its just defend xml schemes to heads
    kindly I don't need import by excel options, I want this custom

    * XML file uploaded as txt, forum didn't allow to upload xml, kindly convert it

    Thanks
    Attached Files Attached Files
    Last edited by davesexcel; 09-29-2020 at 06:52 AM.

  2. #2
    Banned User!
    Join Date
    02-06-2020
    Location
    Iowa City, IA, USA
    MS-Off Ver
    2016 - 365 / 2007
    Posts
    2,014

    Re: Add date file via vba

    why is your post written in such big letters? I don't think some will like that. but at any rate....

    excel CAN import XML data. it is in the interface menu, if you care to look. in terms of selecting a file to get data from, you will need to take a look at this coding concept:

    filedialog
    https://docs.microsoft.com/en-us/off...ion.filedialog

    in terms of getting data OUT of a file by way of a data stream (which is called I/O), you need to take a look at these:

    openTextFile
    https://docs.microsoft.com/en-us/off...extfile-method

    readline
    https://docs.microsoft.com/en-us/off...eadline-method

    input statement
    https://docs.microsoft.com/en-us/off...inputstatement

  3. #3
    Forum Contributor
    Join Date
    07-14-2019
    Location
    Dubai
    MS-Off Ver
    2019
    Posts
    919

    Re: Add date file via vba

    thanks for reply, I know about import xml in excel but that not help me

    thanks for ur links but I need ready vba code if there, I am not pro with writing vba code

    Thanks

  4. #4
    Banned User!
    Join Date
    02-06-2020
    Location
    Iowa City, IA, USA
    MS-Off Ver
    2016 - 365 / 2007
    Posts
    2,014

    Re: Add date file via vba

    upload your file, and specify (give an example of) what information you want to get out of the XML file and where you want to put it in the worksheet. someone will surely help get it started.

  5. #5
    Forum Contributor
    Join Date
    07-14-2019
    Location
    Dubai
    MS-Off Ver
    2019
    Posts
    919

    Re: Add date file via vba

    I upload excel file with xml file

    The excel has original Table sheet and settings table sheet
    I want if I click import, system allow me to select xml file
    then macro read the file I choose, and see my setting table
    and paste only values of all equals data as I wrote in settings table, in the original table
    paste only values without changing anything or format

    I mention two heading in settings sheet, after I get the macro code I will add my others settings, it will be same idea.. its just defend xml schemes to heads
    kindly I don't need import by excel options, I want this custom

    * XML file uploaded as txt, forum didn't allow to upload xml, kindly convert it

    Thanks
    Attached Files Attached Files

  6. #6
    Banned User!
    Join Date
    02-06-2020
    Location
    Iowa City, IA, USA
    MS-Off Ver
    2016 - 365 / 2007
    Posts
    2,014

    Re: Add date file via vba

    well, now I (or others) can probably help you. however, what you have said is still unclear. these words by you:
    and see my setting table
    and paste only values of all equals data as I wrote in settings table, in the original table
    all equals data? what does that mean? it sounds like you want to COPY data that is in your original table, TO the settings table. is that what you want? because there is NO data in your original table. if you only want to copy specific XML data out of the XML file and into the settings table, you need to specify what that is. more than likely, if you can give this info, I or someone else will get you started. but personally, I'm not going to do it all for you. I'll give you a pointer to start.

    by the way, the data in your XML is NOT Xml-formatted data.

  7. #7
    Forum Contributor
    Join Date
    07-14-2019
    Location
    Dubai
    MS-Off Ver
    2019
    Posts
    919

    Re: Add date file via vba

    I want copy data from xml file.. to orginal table.. not all xml schemes.. only schemes that i select it in settings table to mentioned heads

  8. #8
    Banned User!
    Join Date
    02-06-2020
    Location
    Iowa City, IA, USA
    MS-Off Ver
    2016 - 365 / 2007
    Posts
    2,014

    Re: Add date file via vba

    well now.....thanks much. THAT was clear and precise! good deal. so, more than likely this will get you there. put this behind your SETTINGS table:

    Please Login or Register  to view this content.
    now, you do the rest.

    https://docs.microsoft.com/en-us/off...eadline-method

    https://docs.microsoft.com/en-us/off...tstream-object

    https://docs.microsoft.com/en-us/off...extfile-method
    Attached Files Attached Files

  9. #9
    Forum Contributor
    Join Date
    07-14-2019
    Location
    Dubai
    MS-Off Ver
    2019
    Posts
    919

    Re: Add date file via vba

    Thank you!.. I will test it tomorrow but as I see in code.. u want to upload specefic xml file.. "c:\xml.txt".. this just a sample.. i want user brower hes Desktop and select the xml file

    and what do u mean by I do the rest? Guid me..
    Thanks again

  10. #10
    Banned User!
    Join Date
    02-06-2020
    Location
    Iowa City, IA, USA
    MS-Off Ver
    2016 - 365 / 2007
    Posts
    2,014

    Re: Add date file via vba

    Quote Originally Posted by e97h View Post
    u want to upload specefic xml file.. "c:\xml.txt".. this just a sample.. i want user brower hes Desktop and select the xml file
    well of course you do. so, if you want to guide the user to CHOOSE a file instead of hard-coding it into the routine that they will run by clicking the button, you need to read these articles:

    https://docs.microsoft.com/en-us/off...nitialfilename

    https://docs.microsoft.com/en-us/off...ion.filedialog

    https://docs.microsoft.com/en-us/off...filedialogtype

    here's some starter code for you:
    Please Login or Register  to view this content.
    Quote Originally Posted by e97h View Post
    and what do u mean by I do the rest? Guid me..
    Thanks again
    what I meant was that: you are smart. I did 80% of the work for you. Now I would expect that you could take that and do wonderful things for yourself by learning from someone like me. there are a lot of good things that come out of that. and if you do give it a try, you'll see exactly what I mean, especially if you learn to do this stuff on your own. so, try it and let me or "us" here know if you get stuck. that's a good way to go about all of this.
    Last edited by vba_php; 09-25-2020 at 07:28 PM.

  11. #11
    Forum Contributor
    Join Date
    07-14-2019
    Location
    Dubai
    MS-Off Ver
    2019
    Posts
    919

    Re: Add date file via vba

    Hey again and thank you again, but I really I dont know what ur code is doing.. its not what i am looking for>> sorry for that

    Maybe I didnt tell clear what exactly I want, soryy my English not very well
    anyway I make video to show you what I want exactly

    hope its clear
    Thanks for your help
    update excel uploaded
    https://drive.google.com/file/d/1pES...ew?usp=sharing
    Attached Files Attached Files

  12. #12
    Banned User!
    Join Date
    02-06-2020
    Location
    Iowa City, IA, USA
    MS-Off Ver
    2016 - 365 / 2007
    Posts
    2,014

    Re: Add date file via vba

    alright, well I guess you do not have much coding experience. you didn't have to show me the video. I knew what you wanted from the beginning. so, since I'm feeling generous today, I will do it for you. but, I would hope you could take what I'm going to do and learn from it. cuz i'm not going to do it again but of course, you can always ask questions here like everyone can. I simply wanted to encourage you to learn how to do it on your own. I do that with everyone. give me an hour or so....

  13. #13
    Forum Contributor
    Join Date
    07-14-2019
    Location
    Dubai
    MS-Off Ver
    2019
    Posts
    919

    Re: Add date file via vba

    Thank you for ur words, I really benefited from the forums

  14. #14
    Banned User!
    Join Date
    02-06-2020
    Location
    Iowa City, IA, USA
    MS-Off Ver
    2016 - 365 / 2007
    Posts
    2,014

    Re: Add date file via vba

    Please Login or Register  to view this content.
    make sure you change the following lines of code and take the spaces out of the lines of text. this forum's security software blocked the actual code because it detected it as HTML code. no surprise there!
    Please Login or Register  to view this content.
    Please Login or Register  to view this content.
    now, you can do what you wish with that. good luck. and you're welcome.
    Attached Files Attached Files

  15. #15
    Forum Contributor
    Join Date
    07-14-2019
    Location
    Dubai
    MS-Off Ver
    2019
    Posts
    919

    Re: Add date file via vba

    WOW! Thanks you!!
    Fantastic work .. Thats exactly what I want

    Now if I want add new rules, I just need to add rule in rules table + add this lines?

    Please Login or Register  to view this content.
    I did this but its noting happened.. I need to add something more?


    One more point, in the xml file I uploaded, there 4 values for PRICE, and 4 for Description
    I don't know why excel didn't detect first PRICE, and detect only 3 value from 4.. would u check?
    Attached Images Attached Images
    Attached Files Attached Files
    Last edited by Undo; 09-27-2020 at 12:20 AM.

  16. #16
    Banned User!
    Join Date
    02-06-2020
    Location
    Iowa City, IA, USA
    MS-Off Ver
    2016 - 365 / 2007
    Posts
    2,014

    Re: Add date file via vba

    Quote Originally Posted by e97h View Post
    WOW! Thanks you!!
    Fantastic work .. Thats exactly what I want

    Now if I want add new rules, I just need to add rule in rules table + add this lines?

    Please Login or Register  to view this content.
    the following lines of code:
    Please Login or Register  to view this content.
    refer to the column NUMBER that description and price are in, in the sheet table. the following line of code:
    Please Login or Register  to view this content.
    is assigned which ever number of column is relevant at the given time the XML line is being read.
    Quote Originally Posted by e97h View Post
    One more point, in the xml file I uploaded, there 4 values for PRICE, and 4 for Description
    I don't know why excel didn't detect first PRICE, and detect only 3 value from 4.. would u check?
    the code I wrote checks the FIRST XML line where the code < item_price > after any given line where < description > is found. and because of that, only one price for each description is put in the sheet called table. if you want to put ALL of the prices that appear after any given line where < description > is found, the code will need to be changed.

  17. #17
    Forum Contributor
    Join Date
    07-14-2019
    Location
    Dubai
    MS-Off Ver
    2019
    Posts
    919

    Re: Add date file via vba

    yea there only one price for each description, but I mean excel skip the first < item_price >
    item_price came before Description it the xml file, I try to replace item_price and make it in IF condition, and move description to elseif, but same, first item price skippd

  18. #18
    Banned User!
    Join Date
    02-06-2020
    Location
    Iowa City, IA, USA
    MS-Off Ver
    2016 - 365 / 2007
    Posts
    2,014

    Re: Add date file via vba

    are you referring to the data in the image? and if so, are you asking me to change the code whereby it skips the first item price and good description? if not, what do you want?
    Attached Images Attached Images

  19. #19
    Forum Contributor
    Join Date
    07-14-2019
    Location
    Dubai
    MS-Off Ver
    2019
    Posts
    919

    Re: Add date file via vba

    I mean macro already skipped first price only.. It must not skip it

    thats why in my image there is 3 prices with 4 descriptions.. first price skiped.. I dont want to skip

  20. #20
    Banned User!
    Join Date
    02-06-2020
    Location
    Iowa City, IA, USA
    MS-Off Ver
    2016 - 365 / 2007
    Posts
    2,014

    Re: Add date file via vba

    rules that must be satisfied for this code to work properly:

    => every product in the XML must have only one line for < description of goods >, < item_price > and < commodity_code >
    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by vba_php; 09-27-2020 at 09:54 AM.

  21. #21
    Forum Contributor
    Join Date
    07-14-2019
    Location
    Dubai
    MS-Off Ver
    2019
    Posts
    919

    Re: Add date file via vba

    Really Thank You for your help
    but macro still didn't read all xml tags successfully, its skip some tags, example in this xml file I have 12 tags in rule, its print only 9 tags, and avoid 3 tags

    PHOTO : "ERROR" mean macro didn't read the line
    I remove unused tags from xml file to be more clear

    really sorry to keep asking, I try to solve it but I cant handle it

    * convert txt to xml, I cant upload xml in fourms
    Thanks
    Attached Images Attached Images
    Attached Files Attached Files

  22. #22
    Valued Forum Contributor Haluk's Avatar
    Join Date
    02-14-2019
    Location
    Turkiye
    MS-Off Ver
    2010 - 64 Bit on Windows-11 (22 H2) 64 Bit
    Posts
    1,147

    Re: Add date file via vba

    You can upload the XML file in a ZIP folder.

    BTW, what I've seen so far is that; your XML files are not properly arranged. Try to add an original working XML file.

    If we have a correct XML file, then the rest of the job is very easy.
    Last edited by Haluk; 09-27-2020 at 12:12 PM.

  23. #23
    Banned User!
    Join Date
    02-06-2020
    Location
    Iowa City, IA, USA
    MS-Off Ver
    2016 - 365 / 2007
    Posts
    2,014

    Re: Add date file via vba

    Quote Originally Posted by Haluk View Post
    your XML files are not properly arranged.
    this is absolutely correct. XML data is always arranged in a hierarchial manner, and yours is not. it is scattered. that's why my code doesn't make a lot of sense, but it really should. It simply does a job, but not necessarily the right job if given clean data.

  24. #24
    Forum Contributor
    Join Date
    07-14-2019
    Location
    Dubai
    MS-Off Ver
    2019
    Posts
    919

    Re: Add date file via vba

    Sorry for that, very good code I understand your point
    Last point and I am embarrassed to ask you again
    can you link the codes with rule table? so I can add and edit rules from table only, so I dont need to edit vba code every time?
    other way tell me what shall I add in vba code every time I want to add more rules, but if you can do it in the table will be very easier
    And thank you again, SOLVED BY VBA_PHP

  25. #25
    Banned User!
    Join Date
    02-06-2020
    Location
    Iowa City, IA, USA
    MS-Off Ver
    2016 - 365 / 2007
    Posts
    2,014

    Re: Add date file via vba

    Quote Originally Posted by e97h View Post
    can you link the codes with rule table? so I can add and edit rules from table only, so I dont need to edit vba code every time?
    yes. keep adding rows of data to your ""reference table"". the one that has the XML tags in it now. then, write in the code a loop that goes from the top row to the bottom and point to the cells you want to capture within each line. like this:
    Please Login or Register  to view this content.

  26. #26
    Forum Contributor
    Join Date
    07-14-2019
    Location
    Dubai
    MS-Off Ver
    2019
    Posts
    919

    Re: Add date file via vba

    but I cant add the code to main code, its hard to me
    would u place it to the file?
    and put same cell range that I have now, then I can edit the range

  27. #27
    Banned User!
    Join Date
    02-06-2020
    Location
    Iowa City, IA, USA
    MS-Off Ver
    2016 - 365 / 2007
    Posts
    2,014

    Re: Add date file via vba

    I think we're getting to the point where you owe me a cookie for this. LOL. or maybe a $10 dollar USA bill? fine. here:
    Please Login or Register  to view this content.
    Attached Files Attached Files

  28. #28
    Banned User!
    Join Date
    02-06-2020
    Location
    Iowa City, IA, USA
    MS-Off Ver
    2016 - 365 / 2007
    Posts
    2,014

    Re: Add date file via vba

    oh hey, I just noticed something. I forgot to change one line to be congruent with what else I changed. this:
    Please Login or Register  to view this content.
    should be this:
    Please Login or Register  to view this content.
    sorry about that!

  29. #29
    Forum Contributor
    Join Date
    07-14-2019
    Location
    Dubai
    MS-Off Ver
    2019
    Posts
    919

    Re: Add date file via vba

    Now not working fine
    I didnt see ur code in last update
    Please Login or Register  to view this content.
    10 items should print with this file
    anyway u deserve the cookies, give me ur payapl
    Attached Files Attached Files

  30. #30
    Banned User!
    Join Date
    02-06-2020
    Location
    Iowa City, IA, USA
    MS-Off Ver
    2016 - 365 / 2007
    Posts
    2,014

    Re: Add date file via vba

    am I to understand that you need more assistance to finish this up? is that what you're asking?

  31. #31
    Forum Contributor
    Join Date
    07-14-2019
    Location
    Dubai
    MS-Off Ver
    2019
    Posts
    919

    Re: Add date file via vba

    if you can, coz still seems not working like I want

  32. #32
    Valued Forum Contributor Haluk's Avatar
    Join Date
    02-14-2019
    Location
    Turkiye
    MS-Off Ver
    2010 - 64 Bit on Windows-11 (22 H2) 64 Bit
    Posts
    1,147

    Re: Add date file via vba

    @e97h;

    As an alternative, you can try the attached workbook.
    Attached Files Attached Files

  33. #33
    Banned User!
    Join Date
    02-06-2020
    Location
    Iowa City, IA, USA
    MS-Off Ver
    2016 - 365 / 2007
    Posts
    2,014

    Re: Add date file via vba

    e97,

    try what Haluk posted.

  34. #34
    Forum Contributor
    Join Date
    07-14-2019
    Location
    Dubai
    MS-Off Ver
    2019
    Posts
    919

    Re: Add date file via vba

    @Haluk

    Thank you!
    Code working fine, its only didn't detect numbers if start with 0

    Untitled.png
    I can hide the error window, but it think its coz zeros problem
    in the photo,
    HS CODE should be 04....
    - and 1 Shoud be 3 zeros
    2 and 3 should be 4 zeros

    I try to set format as text but same
    Attached Files Attached Files

  35. #35
    Valued Forum Contributor Haluk's Avatar
    Join Date
    02-14-2019
    Location
    Turkiye
    MS-Off Ver
    2010 - 64 Bit on Windows-11 (22 H2) 64 Bit
    Posts
    1,147

    Re: Add date file via vba

    Seems, a Schema file should be used also with the XML file..... i don't have much time now.

  36. #36
    Forum Contributor
    Join Date
    07-14-2019
    Location
    Dubai
    MS-Off Ver
    2019
    Posts
    919

    Re: Add date file via vba

    yea its xml.. anyway thank you good job

  37. #37
    Valued Forum Contributor Haluk's Avatar
    Join Date
    02-14-2019
    Location
    Turkiye
    MS-Off Ver
    2010 - 64 Bit on Windows-11 (22 H2) 64 Bit
    Posts
    1,147

    Re: Add date file via vba

    But, you can apply a custom format to cell A10 as shown in the picture below and then try the code again to see...
    Attached Images Attached Images

  38. #38
    Forum Contributor
    Join Date
    07-14-2019
    Location
    Dubai
    MS-Off Ver
    2019
    Posts
    919

    Re: Add date file via vba

    this code only allow me to see the value like I want, but actually its not the value
    when I copy it and paste value only, zeros gone also when export the xml, zeros not there

    ur code totaly fine, but why this zeros missing?

  39. #39
    Valued Forum Contributor Haluk's Avatar
    Join Date
    02-14-2019
    Location
    Turkiye
    MS-Off Ver
    2010 - 64 Bit on Windows-11 (22 H2) 64 Bit
    Posts
    1,147

    Re: Add date file via vba

    As I've mentioned in message #35, you must use a Schema file to match the data type and it must be associated with the XML file.

    Download the attached documents. The XML file and the Schema file must be in the same folder. Excel file can be placed anywhere ...
    Attached Files Attached Files
    Last edited by Haluk; 09-29-2020 at 04:12 AM.

  40. #40
    Forum Contributor
    Join Date
    07-14-2019
    Location
    Dubai
    MS-Off Ver
    2019
    Posts
    919

    Re: Add date file via vba

    Hey, What you edit in excel rather than add schema in xml file?
    I see its working for old xml files without I mention scheme in xml file

  41. #41
    Valued Forum Contributor Haluk's Avatar
    Join Date
    02-14-2019
    Location
    Turkiye
    MS-Off Ver
    2010 - 64 Bit on Windows-11 (22 H2) 64 Bit
    Posts
    1,147

    Re: Add date file via vba

    Because; when you import the XML file associated with a Schema file into the Excel file, the schema structure is integrated into the Excel file automatically and can be used with other XML files having the same nodes and properties.

    This goes on until you delete or change the Schema in the Excel file.

  42. #42
    Forum Contributor
    Join Date
    07-14-2019
    Location
    Dubai
    MS-Off Ver
    2019
    Posts
    919

    Re: Add date file via vba

    mean the mapped xml file.. has that line for using the scheme?

  43. #43
    Valued Forum Contributor Haluk's Avatar
    Join Date
    02-14-2019
    Location
    Turkiye
    MS-Off Ver
    2010 - 64 Bit on Windows-11 (22 H2) 64 Bit
    Posts
    1,147

    Re: Add date file via vba

    Yes, it is the following line where the schema is declared as an attribute to the root element of the XML structure.

    Please Login or Register  to view this content.

  44. #44
    Forum Contributor
    Join Date
    07-14-2019
    Location
    Dubai
    MS-Off Ver
    2019
    Posts
    919

    Re: Add date file via vba

    Thank you for helping, solved

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. How to check Last Modified Date on Temp File and compare it to original/parent file?
    By CaffeinatedCoder in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-23-2016, 07:42 PM
  2. Open File With file name has format date and time and copy sheets in it
    By stryka in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-16-2015, 06:01 AM
  3. [SOLVED] Saving MASTER file, automatically remove part of file name and append current date?
    By EnigmaMatter in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 09-10-2014, 08:13 AM
  4. Replies: 0
    Last Post: 08-05-2014, 12:46 PM
  5. check if file exists and opening it based on file date
    By JasperD in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 04-26-2014, 03:45 AM
  6. Macro to Download csv file from a dynamic date based url to a specified file location
    By srimani202002 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-23-2014, 07:17 AM
  7. Finding File Creation date, saved date and last modified date
    By david systems in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-22-2013, 05:49 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1