Jump to content

Word Document 'Save as' without a dialogue box


Recommended Posts

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

 

Link to comment
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

Link to comment
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 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
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

Link to comment
Share on other sites

Does the file already exist?

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

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

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
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!

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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
Link to comment
Share on other sites

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

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...