[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 432
  • Last Modified:

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

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 normal.dot, 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
0
vamail2
Asked:
vamail2
  • 2
  • 2
  • 2
  • +1
3 Solutions
 
GrahamSkanCommented:
In Word, you could try the old WordBasic method:

WordBasic.DisableAutoMacros
0
 
broro183Commented:
In Excel you can try adding
application.enableevents = false
'workbooks.open(...)
'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: http://www.excelforum.com/excel-programming/384353-using-vba-to-disable-macros-when-opening-files.html

hth
Rob
0
 
Rory ArchibaldCommented:
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.
Rory

PS Hi, Rob - nice to have you here.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
vamail2Author Commented:
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.
0
 
Rory ArchibaldCommented:
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)
0
 
vamail2Author Commented:
@rorya  Thank you.  Appreciate it very much.
0
 
broro183Commented:
hi everyone,

Vamail2,
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

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

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
  • 2
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now