acekz
asked on
Create word Object - CreateObject("Word.Application")
I am trying to create a Word Object using .asp with 'CreateObject("Word.Applic ation")' 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.
"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.
So you have MS Word installed on your web server?
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. Applicatio n")
HTH
- Anthony
Server.CreateObject("Word.
HTH
- Anthony
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.Applica tion")
WordApp.visible = false
strFileName = strDocName + ".htm"
Response.Write(strDocName + "<br>")
Response.Write(strFileName )
WordApp.Documents.Open("C: \windows\d esktop\tes tfile\" + strFileName)
numChars=WordApp.ActiveDoc ument.Char acters.Cou nt
set myrange = WordApp.ActiveDocument.Ran ge(0,numCh ars-20)
myrange.select
WordApp.Selection.Copy
WordApp.ActiveDocument.clo se
WordApp.Documents.add
WordApp.Selection.paste
strFileName = strDocName + ".doc"
WordApp.ActiveDocument.Sav eAs("C:\wi ndows\desk top\testfi le\" +strFileName)
WordApp.ActiveDocument.Clo se
WordApp.Quit
set WordApp = Nothing
Response.Redirect(strFileN ame)
%>
</SCRIPT>
<BODY>
</BODY>
</HTML>
<%
'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.Applica
WordApp.visible = false
strFileName = strDocName + ".htm"
Response.Write(strDocName + "<br>")
Response.Write(strFileName
WordApp.Documents.Open("C:
numChars=WordApp.ActiveDoc
set myrange = WordApp.ActiveDocument.Ran
myrange.select
WordApp.Selection.Copy
WordApp.ActiveDocument.clo
WordApp.Documents.add
WordApp.Selection.paste
strFileName = strDocName + ".doc"
WordApp.ActiveDocument.Sav
WordApp.ActiveDocument.Clo
WordApp.Quit
set WordApp = Nothing
Response.Redirect(strFileN
%>
</SCRIPT>
<BODY>
</BODY>
</HTML>
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?
"ActiveX component can't create object: 'Word.Application'"
any thoughts? justinbillig, you still there?
Did you try my suggestion?
- Anthony
- Anthony
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
As an aside, I wonder if NAV is interfering with your script?
FtB
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"...
I don't think that NAV is interfering because I have "Script Blocking" set to "OFF"...
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.
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.
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...
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
FtB
ASKER
Possibly...depends on client host, etc...what do you have in mind?