Word & Excel Automation:  Open doc/books without default "auto" execs, macros, templates, etc..

Posted on 2011-05-08
Last Modified: 2012-05-11
I am using automation to start Excel and Word and just use their respective Documents.Add() fucntion to open them up with blank documents/workbooks.  But, I don't want those applications to fireoff any auto macros or open up large default templates the user may have set in their options?

When I call Word.Documents.Add() and Excel.Workbooks.Add(), do they load the whatever the user has set as their, personal.xls and all the other default templates etc..?  If so, how can I prevent that from happening when automating these Office apps?

Thanks in advance
Question by:vamail2
    LVL 76

    Assisted Solution

    In Word, you could try the old WordBasic method:

    LVL 10

    Assisted Solution

    In Excel you can try adding
    application.enableevents = false
    'and turning them back on after the file is open using
    application.enableevents = true

    Open in new window

    fwiw, here is a link I came across while checking my suggestion:

    LVL 85

    Accepted Solution

    If you are automating Excel (I don't know about word) then the user's startup files such as templates and addins do not get loaded unless you explicitly load them.

    PS Hi, Rob - nice to have you here.

    Author Comment

    wow.  All of these are great anwsers for different reasons.  

    @rorya - Thanks.  that makes sense and answers my concerns.  But I thought the docs said that it loads default if you pass Type.missing for the doc name etc... (which I would assume picks up on personal.xls.  I do know for sure picks up the settings like default number of sheets)

    @broro183 - great idea when I do have to load docs

    @graham - Wow.  great idea and I could use this for other things.
    LVL 85

    Expert Comment

    by:Rory Archibald
    Personal.xls is not a template - it's a specific file for storing macros. It should not be opened if you automate Excel.
    The number of sheets and default fonts etc are application settings - they are not part of a template file as such. (You can create a template file called book.xlt but that again should be ignored when automating Excel from VB)

    Author Comment

    @rorya  Thank you.  Appreciate it very much.
    LVL 10

    Expert Comment

    hi everyone,

    Thanks for the points :-)
    On re-reading your first post, I see that I missed a lot of your questions & am glad that Rory helped you out on the Excel side.

    hi Rory :-)
    Thanks, it's good to be here. I came along to get a free membership so I could borrow some ready-made AS400 solutions and have since decided that I should earn my keep while I'm here ;-)


    Rob Brockett
    Kiwi in the UK
    Always learning & the best way to learn is to experience...

    Featured Post

    Highfive Gives IT Their Time Back

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    Introduction This Article briefly covers methods of calculating the NPV and IRR variants in Excel as well as the limitations in calculating and interpreting IRR results. Paraphrasing Richard Shockley, author of my favourite finance reference tex…
    Microsoft Word is a program we have all encountered at some point, but very few of us have dug deep into its full scope of features, let alone customized it to suit our needs. Luckily making the ribbon (aka toolbar, first introduced in Word 2007) wo…
    This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.
    This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.

    734 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now