Link to home
Start Free TrialLog in
Avatar of acekz
acekzFlag for United States of America

asked on

Create word Object - CreateObject("Word.Application")

I am trying to create a Word Object using .asp with 'CreateObject("Word.Application")' I am getting the following error:

"ActiveX component can't create object: 'Word.Application'"

What's the deal? What do i need to get this to work? is it stinkin' XP SP2??? Please help ASAP.
Avatar of justinbillig
justinbillig

So you have MS Word installed on your web server?
Avatar of acekz

ASKER

Well, I am testing this on my personal web server on my XP Pro machine and I do have Word installed.
Use:
Server.CreateObject("Word.Application")

HTH
- Anthony
ASKER CERTIFIED SOLUTION
Avatar of fritz_the_blank
fritz_the_blank
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
If you are nonetheless hell-bent on doing this, then the code looks like:

<%
'This codes assumes the existence of a folder named "testfile" on the desktop
'It will be neccessary to change the path when implemented
dim strDocName, strFileName
strDocName = Request("DocName")
dim WordApp
set WordApp = CreateObject("Word.Application")
WordApp.visible = false
strFileName = strDocName + ".htm"
Response.Write(strDocName + "<br>")
Response.Write(strFileName)
WordApp.Documents.Open("C:\windows\desktop\testfile\" + strFileName)
numChars=WordApp.ActiveDocument.Characters.Count
set myrange = WordApp.ActiveDocument.Range(0,numChars-20)
myrange.select
WordApp.Selection.Copy
WordApp.ActiveDocument.close
WordApp.Documents.add
WordApp.Selection.paste
strFileName = strDocName + ".doc"
WordApp.ActiveDocument.SaveAs("C:\windows\desktop\testfile\" +strFileName)
WordApp.ActiveDocument.Close
WordApp.Quit
set WordApp = Nothing
Response.Redirect(strFileName)
%>
</SCRIPT>
<BODY>
</BODY>
</HTML>
Avatar of acekz

ASKER

Thanks for the try, fritz, but this is exactly the code I am using. The error is:

"ActiveX component can't create object: 'Word.Application'"

any thoughts? justinbillig, you still there?
Did you try my suggestion?

- Anthony
Avatar of acekz

ASKER

Yes, that gave me an error saying need "Server" object...
Did you catch my post about MS warning you not to do this?

As an aside, I wonder if NAV is interfering with your script?

FtB
Avatar of acekz

ASKER

I did catch your warning...I am just testing right now...clients sometimes demand what you don't suggest if you know what I mean.
I don't think that NAV is interfering because I have "Script Blocking" set to "OFF"...
Avatar of acekz

ASKER

So what are other suggestions to get this working or other solutions to get me the same result?
To be honest I wouldnt know. It's a really bad thing to do ( for security reasons ) if you need to write text to files i suggest using the FileScripting Object

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbenlr98/html/vaobjfilesystemobject.asp

I agree with FTB



- My name is justin billig, and I approve this anwer.
Avatar of acekz

ASKER

OK...the goal is to autofill a document with a user's credentials after logging in...i.e. an employee filling out HR documents online...the essentials are already filled in based on data stored in the DB for that user...
I totally understand what you guys are saying and we probably are not going to use the createObject method here, but is there any other way?

The only thing I can think of is to save the Word Documents out as html pages, but doing that adds a bunch of crap to the html and such...

So anyway, any other suggestions would be great...is there a way to write the info to a text file with certain formatting and then save it with a .doc extension like you can do with excel?

Anyway, let me know and I will split the points between FTB and JB...thanks again...
There are some components out there designed to do this. Can you install 3rd-party components on your server?


FtB
Avatar of acekz

ASKER

Possibly...depends on client host, etc...what do you have in mind?
Something along the lines of this:

http://www.mylittletools.net/scripts/en/mlw/

FtB