srwhale

Word Document 'Save as' without a dialogue box

12 posts in this topic

Hello all,

I've got a script that opens up an existing word template (docx), does some replacements and pastes in a load of stuff from certain text files, then does a save as with a particular file name. Except I'm running into the problem that the SaveAs opens a dialogue box even though the file path specified seems to be valid.

Is there a way of making it so the dialogue box doesn't show up? This script loops hundreds of times so I would to not have to enter the file name each time! The folder I am using already exists, but the file does not.

I've been scratching my head over this for a few days now. Below is a cut down version of my script - is there anything that I am doing wrong?

I'm working on Windows 7 and Word 2013, if that's relevant.

Thanks,

~srwhale

 

#include <Array.au3>
#include <File.au3>
#include <Word.au3>

$sNewFileLocation = "D:\OCR\AutoDocx" ;This folder already exists
Global $aFileNames[4] = ["Foo1","Foo2","Bar1","Bar2"]
Global $sTemplate = "D:\OCR\IS_template_2.docx"


For $i = 1 to UBound($aFileNames)-1
    Local $oWord = _Word_Create()
    $oDoc = _Word_DocOpen($oWord,$sTemplate,Default,Default,False) ;'False' = Not read only

    ;Makes replacements, pastes stuff in etc.

    $sNewDocxLocation = $sNewFileLocation&"\IS"&$aFileNames[$i]&".docx"
    MsgBox(0,"Info","Saving to "&$sNewDocxLocation)
    _Word_DocSaveAs($oDoc,"'"&$sNewDocxLocation&"'",$WdFormatDocumentDefault) ;I've tried several things - double quotes in case there is a space, trying different formats or omitting that bit, etc.
    _Word_DocClose($oDoc)
Next

 

Share this post


Link to post
Share on other sites



hello,

ive tried above code and at first it didn't save the file but then i removed the " ' "& before and after $sNewDocxLocation and it saves with no problems or dialogue boxs.

so try without it...why do you need that "'"& anyway?...

windows 8 word 2010

Share this post


Link to post
Share on other sites

You need to pass a string to _Word_DocSaveAs - which you already have by using a variable. Remove "'" and it should work. 


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Hi,

I’ve removed both “’” bits but annoyingly I still seem to get the dialogue box. They were only there just in case any of my file paths had spaces in as I was under the impression that this can cause strange behaviour without a second set of quotes.  Could the dialogue box problem be something specific to Word 2013 maybe? I’m on AutoIT 3.3.14.1, the newest I believe.

~srwhale

Share this post


Link to post
Share on other sites

Does the file already exist?


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Nope. I have a screenshot:

saveAs.jpg

Share this post


Link to post
Share on other sites

Thanks. Will have a look on Monday when I return to my office. 

1 person likes this

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

Do you have formulas, tables, pictures or the like in the document? If so, there is a bug that causes save as loop when trying to save as docx  

Check this Link, it may be related to this problem.

 

 

Edited by CrypticKiwi

Share this post


Link to post
Share on other sites

That sounded like it might be it: the .docx was a .dotx before I converted it, and there are images and tables inside it as well as a contents page. But I made a new blank .docx and tried running the SaveAs script on that and the same dialogue box still appears. 

It was a good idea though!

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

Until I figure something out lets make sure you are not using any global templates/add-ins etc.. so go to 
Tools/Templates and Add-Ins and see if there are any global templates 
or add-ins listed.

Also try running word in safe mode by pressing the windows button + r then typing winword.exe /safe then try saving using your script also try /a .

you can also try to open and repair the file before saving.

Edited by CrypticKiwi

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

Thanks for your patience CrypticKiwi! Got it -  spotted a dodgy COM add-in called abDocs (think it's an Acer laptop cloud synch thing), and disabling that has stopped the dialogue box. Things are saving fine now, whoop whoop. :lol: Even on the .docx with pictures/contents/tables!

 

Thanks again,

~srwhale

Edited by srwhale
typo - delete repeated word

Share this post


Link to post
Share on other sites

Ah, again a misbehaving add-in.
Happens quite often lately.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now