Can anyone see what is wrong with this script?
set thetemplate to thePath &“Magic Briefcase:Practice:BarristerBase:Templates:Advice.dot”
Set docHome to thePath & “Magic Briefcase:Practice:BarristerBase:Documents”
Set doccc to docHome&“:”&thename
Display dialog doccc
tell application "Microsoft Word"
activate
open thetemplate
set fileName to name of active document
save as fileName file name doccc
end tell
When I run it it tells me that the document doesn’t understand the save as command:
Result:
error “Microsoft Word got an error: "Document6" doesn’t understand the save as message.” number -1708 from “Document6”
Model: Macbook Pro 13"
AppleScript: 2.5
Browser: Firefox 16.0
Operating System: Mac OS X (10.8)
I don’t have Word, but the usual syntax for a ‘save’ command is:
By the way, MacScripter’s fora have special [applescript] and [/applescript] tags and it’s considered good practice to wrap AppleScript code in these when posting. They cause the code to appear in a box with a clickable link which opens the code in the reader’s default script editor. Either click the “Applescript” button above the posting window and paste the compiled code between the tags which appear, or paste the code first, select it, and then click the button. Or of course you can simply write the tags into the post text.
save as (verb)Saves the document with a new name or format. (from Microsoft Word Suite)
Command Syntax
save as document ¬
file name text ¬
.
Parameters
direct parameter - required - document
file name - optional - text The name for the document. The default is the current folder and file name. If a document with the specified file name already exists, the document is overwritten without the user being prompted first.
This works (obviously the variables are not defined in this snippet):
ell application "Microsoft Word"
activate
open thetemplate
save as active document file name doccc
end tell
My concern then was that if, for some reason, the template I opened was not the active document (this may be impossible - I don’t know) a different document to the one I intended would get saved with the “doccc” name.
Hence my attempt to immediately identify the active document - on reflection I am not sure that would solve that issue anyway.
It is working so i guess I’ll chug along with this version until I encounter the problem.
Thanks for your help.
Perhaps someone can help me… I am following these directions fine, but this script will not work… why?
property ExtensionsList : {"doc", "docx"}
tell application "Finder"
set the source_folder to (choose folder with prompt "Pick the folder containing the documents to process:")
set these_documents to (every item of the source_folder whose name extension is in the ExtensionsList) as list
repeat with i from 1 to the count of these_documents
set this_item to item i of these_documents
set {fname, fextension} to paragraphs of (do shell script "echo " & quoted form of (this_item as text) & " | sed -E 's/.+:(([^:]+)[.]([^:.]*)|([^:.]+)):?$/\\2\\4\\" & linefeed & "\\3/'")
set thisPath to quoted form of (POSIX path of (this_item as alias))
set newName to fname & ".pdf"
tell application "Microsoft Word"
set currentDoc to open file name (this_item as string)
delay 2
save as currentDoc file format format PDF file name (fname & ".pdf")
close currentDoc saving no
end tell
end repeat
end tell
I should point out that the error is the same as the original poster - Word returns a “XYZ.doc” cannot save, blah blah error.
the open command of Word does not return the opened document as the result.
.
tell application "Microsoft Word"
open this_item
delay 2
save as active document file format format PDF file name (fname & ".pdf")
close active document saving no
end tell
.
Thank you so much for that. I suppose that I should have been more precise in my question. I only had attempted the “set… open” format to try to avoid a problem with Save As…
In the code below, I just want to save the opened document to the same folder, as a PDF, with the filename + .pdf extension. No matter what format I type the “Save As” command, Word throws an error, saying “Microsoft Word got an error: “Brie Coellner - midterm_coellner.docx” doesn’t understand the save as message.” I cannot figure out how Word wants to reference the open document. If I try
save as active document file format PDF file name (fname & ".pdf")
it throws the same error, saying that “active document” does not understand the save as message.
tell application "Microsoft Word"
open this_item
delay 3
set currentDoc to the name of the active document
save as currentDoc file format format PDF file name (fname & ".pdf")
close currentDoc saving no
end tell
in your script you assign the name of the active document to currentDoc instead of the document itself.
Try this
tell application "Microsoft Word"
open this_item
set currentDoc to active document
set fName to name of active document
save as currentDoc file format format PDF file name (fName & ".pdf")
close currentDoc saving no
end tell
Thanks Stefan, but that doesn’t work.
Microsoft Word got an error: “Olivia L Fraustino - mark midterm.docx” doesn’t understand the save as message.
where the item in quotes is the name of the open file. The problem seems to be that Word is expecting something different than the name of the doc or a reference to “this_doc” or anything else I can think of.
Perhaps something between Lion and Mountain Lion? I am using MtnLion and Word 2011. I am going to guess that the whole SAVEAS command is broken, since I also cannot get it to execute the same command in a VBA macro.
tell application "Microsoft Word"
activate
open thetemplate
save as active document file name doccc
end tell
It is running on el capitan with word 2016 on one machine with no problems.
It was running with no problems on Yosemite/Word 2016 with no problems when it suddenly threw the error “Expected end of line, etc. but found class name.”
By way of background the script is actually in a filemaker solution and merges data from that into a word template.
Any and all help greatly appreciated - be gentle I am an amateur.
Thanks.