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

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

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

I'm getting the error below when executing the below code on Windows 7 64bit Office 2010 machines at my company.

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

Open in new window


SCRIPT:
dim word
set word=createobject("Word.Application")
word.visible=true

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?
0
support01
Asked:
support01
  • 2
1 Solution
 
TommySzalapskiCommented:
Try not calling the variable 'word'
Call it objWord or wordApp or something.
0
 
rejoinderCommented:
There is a site which details similar issues - the fix for them was a MS hotfix.
http://social.msdn.microsoft.com/Forums/en-HK/worddev/thread/403c83c7-b55d-438a-b60b-9843ba9207f7

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")
word.visible=true

isWorking = false
escapeFromLoop = 0
do
	escapeFromLoop = escapeFromLoop + 1
	set document = word.documents.add()
	if err.number <> 0 then
		err.clear()
		wscript.sleep 500
	else
		isWorking = true
	end if
	if escapeFromLoop = 10 then
		wscript.echo "Error adding Word object"
		wscript.quit
	end if
loop until isWorking = true

Open in new window

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

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

Open in new window

0
 
rejoinderCommented:
Glad that helped and thanks for the points :-)
0

Featured Post

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!

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