Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • putdocx save without closing?

    putdocx clear allows to close the active document without saving, but is there a way to save without closing? I want to save the active document in a folder, then keep the same document active to add more things, then save the updated document to a different folder. For example:

    Code:
    putdocx begin
    putdocx paragraph
    putdocx text ("Info")
    
    mkdir "folder1"
    putdocx save "folder1/doc1.docx", replace  // first doc saved OK
    
    putdocx paragraph  // error, doc is no longer active; how do I save without closing?
    I tried preserve and restore, but putdocx save seems to ignore it:
    Code:
    putdocx clear
    putdocx begin
    putdocx paragraph
    putdocx text ("Info")
    
    preserve
    putdocx save "folder1/doc1.docx", replace
    
    restore
    putdocx paragraph  // error, document was closed anyway
    Any help would be greatly appreciated. Thanks!
    Last edited by Manuel PenaH; 07 Mar 2022, 14:21.

  • #2
    Not from Stata, you can't do that. Saving the file is effectively closing it, and to add to it, you just re-open the file. It is likely easier to save the file only when you are done.

    Comment


    • #3
      Thank you so much, Leonardo. Do you know if it is possible to reopen a document that was previously closed? I guess I could open a new doc, repeat the same code, then add to it and save, but I would like to avoid this. Thank you!

      Comment


      • #4
        Sorry, I mislead you a bit in #2 where I was thinking more of Excel. You cannot re-open the docx file once it's saved, but you can append to it. See -help putdocx append- for more. The recommendation then is to either open the file once, adding to it as you go, or else create individual docx files as pieces of the larger document, and append them all at the end.

        Comment


        • #5
          That's a great idea -- thank you so much, Leonardo!

          Comment

          Working...
          X