Error: Object Required: 'documents.add'  Code: 800A01A8 On Windows 7 Office 2010

Posted on 2011-10-04
Last Modified: 2012-05-12
I'm getting the error below when executing the below code on Windows 7 64bit Office 2010 machines at my company.

Script: word.vbs
Line 6 Char 1
Error: Object Required: 'documents.add' 
Code: 800A01A8
Source: MS VBScript runtime error

Open in new window

dim word
set word=createobject("Word.Application")

dim document
set document=word.documents.add

Open in new window

The code was given to me for testing purposes by a 3rd party application support company. It should just open a blank document in Word.

I've tried this on many different machines running a variety of Windows 7 64bit Office 2010 machines and get a seemly random mix of errors and successes. I have tried fully enabling macros and lowering security.

On one machine the script will return the error if Word is already open but will work successfully if not.

Does anyone know of any prevailing conditions or settings which will determine whether this will work?
Question by:support01
    LVL 37

    Expert Comment

    Try not calling the variable 'word'
    Call it objWord or wordApp or something.
    LVL 14

    Accepted Solution

    There is a site which details similar issues - the fix for them was a MS hotfix.

    Can you try the code below to see if that works for your toubled machines?
    on error resume next
    Dim word
    Dim document
    Dim isWorking
    Dim escapeFromLoop
    set word = createobject("Word.Application")
    isWorking = false
    escapeFromLoop = 0
    	escapeFromLoop = escapeFromLoop + 1
    	set document = word.documents.add()
    	if err.number <> 0 then
    		wscript.sleep 500
    		isWorking = true
    	end if
    	if escapeFromLoop = 10 then
    		wscript.echo "Error adding Word object"
    	end if
    loop until isWorking = true

    Open in new window


    Author Closing Comment

    Thanks rejoinder, haven't tried hotfix but new line of code works a treat

    dim wordapp
    set wordapp=createobject("Word.Application")
    Wscript.Sleep 500
    dim document
    set document=wordapp.documents.add

    Open in new window

    LVL 14

    Expert Comment

    Glad that helped and thanks for the points :-)

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    A short article about problems I had with the new location API and permissions in Marshmallow
    Outlook Free & Paid Tools
    The viewer will learn how to simulate a series of coin tosses with the rand() function and learn how to make these “tosses” depend on a predetermined probability. Flipping Coins in Excel: Enter =RAND() into cell A2: Recalculate the random variable…
    Learn how to create and modify your own paragraph styles in Microsoft Word. This can be helpful when wanting to make consistently referenced styles throughout a document or template.

    746 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

    14 Experts available now in Live!

    Get 1:1 Help Now