Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[no subject]



1. The file is open in its native program, probably behind the Stata window.  The operating system will not allow Stata to overwrite the file, but Stata does not generate an error message.  This is likely a function of messages sent by the OS, rather than a shortcoming in Stata.

2. The file is changed on disk, but Word for some reason fails to "recognize" the fact.  This is rarer, and probably driven by some sort of cacheing activity.

3. In a variant of (1), the document is closed, but somewhere in the Word -- OS -- universe chain of event, the appropriate "lock-bit" has not been unset, again making the OS resistant to overwriting the file.

I can confirm (1) directly.  (2) and (3) are the result of experimentation, speculation, and desperation.  Basically, I've come to view "replace" as effectively meaning, "If 'replace' isn't specified, refuse to overwrite the file.  If 'replace' is specified, do what you can given other conditions on the computer, but don't freak out if it doesn't work."

At a minimum, being sure the file to be replaced is not open in Word may help.  The next step would probably be to make sure Word is closed, which seems to help what I assume to be problems (2) and (3).  Failing that, I often turn to a mix of threats and cajoling language towards the computer.

More practically, I often include a short set of commands in my do files that go out to the shell and run an AppleScript via oascript to make the file is closed in Word before I try to write over it.  That addresses (1) with minimum effort.  I will sometime include a similar command post output to open the new file in Word.  I'm unsure is something similar is possible under Windows.

I hope that helps.  Frustrating, I recognize.

Glenn


Glenn Hoetker 
Arizona State University | W. P. Carey School of Business 
Dean's Council Distinguished Scholar & Associate Professor 
Affiliate Professor   Sandra Day O'Conner College of Law 
Senior Sustainability Scholar   Global Institute of Sustainability 
Faculty Fellow   Center for Science, Law & Innovation 
[email protected]  | http://hoetker.faculty.asu.edu | 480-965-4566 

On Dec 6, 2013, at 8:51 AM, Friedrich Huebler <[email protected]> wrote:

> I am experimenting with the creation of .docx files and don't know how
> to specify the -replace- option. According to -help mf__docx-,
> documents are saved with this command:
> 
> _docx_save(dh, string scalar filename [, real scalar replace])
> 
> Take this example, adapted from -help mf__docx-.
> 
> * Create a document
> mata:
> dh = _docx_new()
> end
> 
> * Add some text
> mata:
> _docx_paragraph_new(dh, "Some text")
> end
> 
> * Save file
> mata:
> res = _docx_save(dh, "example.docx")
> end
> 
> * Replace file
> mata:
> res = _docx_save(dh, "example.docx", replace)
> end
> 
> The last command results in an error message.
> 
> . * Replace file
> . mata:
> ------------------------------------------------- mata (type end to
> exit) --------------------------------------
> : res = _docx_save(dh, "example.docx", replace)
>                 <istmt>:  3499  replace not found
> (0 lines skipped)
> ----------------------------------------------------------------------------------------------------------------
> r(3499);
> 
> I tried different variations of the -replace- option with the same
> result. What am I doing wrong?
> 
> Friedrich
> *
> *   For searches and help try:
> *   http://www.stata.com/help.cgi?search
> *   http://www.stata.com/support/faqs/resources/statalist-faq/
> *   http://www.ats.ucla.edu/stat/stata/


*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index