+ Reply to Thread
Results 1 to 17 of 17

Reading the XML of a workbook

  1. #1
    Valued Forum Contributor ImranBhatti's Avatar
    Join Date
    03-27-2014
    Location
    Rawalpindi,Pakistan
    MS-Off Ver
    Office 365
    Posts
    1,784

    Reading the XML of a workbook

    Hi,

    By changing the extension of an xlsm file to .zip and extracting that zip folder we can see a file named "comments1.xml"

    Is there a way to read comments from that file without zipping workbook/without opening the workbook? using VBA or any other language?
    Teach me Excel VBA

  2. #2
    Valued Forum Contributor ImranBhatti's Avatar
    Join Date
    03-27-2014
    Location
    Rawalpindi,Pakistan
    MS-Off Ver
    Office 365
    Posts
    1,784

    Re: Reading the XML of a workbook

    Any one please...?

  3. #3
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,441

    Re: Reading the XML of a workbook

    Not with VBA.
    You might find another language has libraries to read a zip file

    Why can you not open the workbook?
    Cheers
    Andy
    www.andypope.info

  4. #4
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: Reading the XML of a workbook

    Yes, there are plenty of examples and libraries on the web for doing this. Why do you want to do this without opening the workbook?

  5. #5
    Valued Forum Contributor ImranBhatti's Avatar
    Join Date
    03-27-2014
    Location
    Rawalpindi,Pakistan
    MS-Off Ver
    Office 365
    Posts
    1,784

    Re: Reading the XML of a workbook

    The reason not to open is very common one "A lot of files are listed in the master workbook and need to quickly read the comments from specific cells of the closed workbooks"

  6. #6
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: Reading the XML of a workbook

    I don't know what that means, what is your objection to opening the workbooks?

  7. #7
    Valued Forum Contributor ImranBhatti's Avatar
    Join Date
    03-27-2014
    Location
    Rawalpindi,Pakistan
    MS-Off Ver
    Office 365
    Posts
    1,784

    Re: Reading the XML of a workbook

    upto 1000 books will take time to
    1:Lopen
    2:read comment
    3: clos
    and those files are also an xlsm template which runs a lot of code on opening.

  8. #8
    Valued Forum Contributor ImranBhatti's Avatar
    Join Date
    03-27-2014
    Location
    Rawalpindi,Pakistan
    MS-Off Ver
    Office 365
    Posts
    1,784

    Re: Reading the XML of a workbook

    Later posted here.

  9. #9
    Valued Forum Contributor ImranBhatti's Avatar
    Join Date
    03-27-2014
    Location
    Rawalpindi,Pakistan
    MS-Off Ver
    Office 365
    Posts
    1,784

    Re: Reading the XML of a workbook

    And posted : here today.

  10. #10
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,291

    Re: Reading the XML of a workbook

    Are you sure there's only ever one sheet in the workbooks?
    Remember what the dormouse said
    Feed your head

  11. #11
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Reading the XML of a workbook

    and those files are also an xlsm template which runs a lot of code on opening
    You can disable auto-open macros before opening the workbooks; see Application.AutomationSecurity.
    Last edited by shg; 12-22-2018 at 01:04 PM.
    Entia non sunt multiplicanda sine necessitate

  12. #12
    Valued Forum Contributor ImranBhatti's Avatar
    Join Date
    03-27-2014
    Location
    Rawalpindi,Pakistan
    MS-Off Ver
    Office 365
    Posts
    1,784

    Re: Reading the XML of a workbook

    Quote Originally Posted by rorya View Post
    Are you sure there's only ever one sheet in the workbooks?
    Thanks rory for the response.
    No I have multiple worksheets in the workbook but need to read comments from only one specific sheet currently.

  13. #13
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,291

    Re: Reading the XML of a workbook

    Then you can't just extract comments1.xml as it may not be the correct sheet's comments. You either need to know the index number of the sheet whose comments you want, or you'll need to parse all the sheetnn.xml files to find the correct one. Then you'll need to find the correct rels file to workout which comment file belongs to it.
    Last edited by romperstomper; 12-27-2018 at 05:43 AM.

  14. #14
    Valued Forum Contributor ImranBhatti's Avatar
    Join Date
    03-27-2014
    Location
    Rawalpindi,Pakistan
    MS-Off Ver
    Office 365
    Posts
    1,784

    Re: Reading the XML of a workbook

    Thanks again

    If I manage to have only one worksheet in the task files, the name of the sheet is same in all task files,then what will be the way to extract comments from that sheet?

    I have a specific range in that sheet that comments of which are needed to read.

  15. #15
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,291

    Re: Reading the XML of a workbook

    Here's some very rough code to get you started.

    Please Login or Register  to view this content.

  16. #16
    Valued Forum Contributor ImranBhatti's Avatar
    Join Date
    03-27-2014
    Location
    Rawalpindi,Pakistan
    MS-Off Ver
    Office 365
    Posts
    1,784

    Re: Reading the XML of a workbook

    Thank you very much rory for your precious time and effort.

    I examined my Task Files they do have multiple sheets but with .zip I see my required Comments are alway in comments3.xml

    What changes do I need in the script if I have a confirmed name of comments.xml file for each Task files?

  17. #17
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    MS365 Apps for enterprise
    Posts
    5,913

    Re: Reading the XML of a workbook

    Since you have Office 2016, here's another approach using Get & Transform (PQ).
    Assuming that you have workbooks changed to .Zip extension already...
    You can use PQ to query it.
    EDIT: Actually it does not need to have .Zip extension. You can simply read xlsx file using fnUnzip.

    Ex: Book1.Zip is stored in "C:\Test" folder. Extracting comment text from comments3.xml

    1. Follow link below and copy custom function as blank query named "fnUnzip" in advanced editor.
    http://sql10.blogspot.com/2016/06/re...erquery-m.html

    2. Add another blank query and use following as source.
    = File.Contents("C:\Test\Book1.zip")

    3. Use fnUnzip custom function to read the content of zip file in advanced editor. Complete "M" should look like below at this point.
    Please Login or Register  to view this content.
    2.JPG

    4. Apply filter to "FileName" column using "comments3.xml" as condition.

    5. Right click on result and choose "xml"

    6. In advance editor, add "Table = #"Imported XML"{1}[Table]{0}[Table]{0}[text]" line. "M" should look like below.
    Please Login or Register  to view this content.
    7. Split the resulting column using custom delimiter "Comment:" at right most delimiter.

    8. Remove 1st column from result and trim the 2nd column. You are left with comment string from comments3.xml
    1.JPG

    Complete "M" code.
    Please Login or Register  to view this content.
    I assumed you only had one comment in comments3.xml. If you need further help. I'd recommend that you upload sample zipped file(s).
    Last edited by CK76; 01-04-2019 at 02:35 PM.
    ?Progress isn't made by early risers. It's made by lazy men trying to find easier ways to do something.?
    ― Robert A. Heinlein

+ 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. [SOLVED] Error Trapping When Reading From Another Workbook
    By redtop91 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 08-06-2014, 02:54 PM
  2. Reading cell from another workbook into a second workbook.
    By tancho321 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 03-27-2013, 07:30 AM
  3. issue reading from another workbook.
    By kieranbop in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-20-2011, 04:16 AM
  4. [SOLVED] Reading values from a closed workbook
    By Graham F in forum Excel - New Users/Basics
    Replies: 4
    Last Post: 05-28-2006, 08:55 AM
  5. Reading information from a closed workbook
    By yhockman1 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-15-2006, 09:30 AM
  6. [SOLVED] Reading from a closed workbook
    By WannaBeExceller in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-22-2006, 12:55 PM
  7. Reading Writing Data from One WorkBook to Another
    By John Pierce in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-30-2005, 05:05 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