Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How do I create an object connection to Word ?

Posted on 1999-10-21
20
Medium Priority
?
298 Views
Last Modified: 2013-12-25
I can create an object connection to Word in VB but cannot find a way to do this in either Jscript or VBscript. Does anyone know if this is possible and how to do it. I try to use the following in VBscript: Set wrd = CreateObject("WORD.APPLICATION.8") but get an error: Command failed. Any help would be appreciated.
0
Comment
Question by:mtomkins
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 9
  • 6
  • 5
20 Comments
 
LVL 5

Expert Comment

by:mayhew
ID: 2145533
To my knowledge, you can't do this on the client side.

But if you do it server side with VBScript (in an asp page, for example) and you have Word installed on the server, you should be fine.
0
 

Expert Comment

by:tmattoneill
ID: 2145630
That is true indeed!  I haven't seen an implementation for it on CS but it would definately work on SS.  In that situation, it would be 100% like the VB (not script) solution.

Do you want to do this on the client side or server side, Mtomkins?

M
0
 

Author Comment

by:mtomkins
ID: 2145695
I would like to do this on the server side. The page is I am using is an asp.
0
Moving data to the cloud? Find out if you’re ready

Before moving to the cloud, it is important to carefully define your db needs, plan for the migration & understand prod. environment. This wp explains how to define what you need from a cloud provider, plan for the migration & what putting a cloud solution into practice entails.

 
LVL 5

Expert Comment

by:mayhew
ID: 2145706
Do you have Word installed on the server?
0
 

Author Comment

by:mtomkins
ID: 2145747
Thanks for your help guys, I tried it with word installed on the server but still get the same error message.
0
 
LVL 5

Expert Comment

by:mayhew
ID: 2145756
Can you post the code and the exact error message?
0
 

Author Comment

by:mtomkins
ID: 2145764
Thanks for your help guys, I tried it with word installed on the server but still get the same error message.
0
 

Author Comment

by:mtomkins
ID: 2145776
Sure, here you go.
Code:
Sub btnView_onClick()
If FormText.FileList.ListIndex = -1 Then Exit Sub
fle = FormText.FileList.Text
Set wrd = CreateObject("WORD.APPLICATION.8")
wrd.Documents.Open fle
wrd.Visible = True
End Sub
Error message:
A Run time error has occured. Do you wish to debug?
Error:Command failed.
0
 

Expert Comment

by:tmattoneill
ID: 2145781
All right, mtomkins, I'll give a shot and give you the code. How bout them apples?

:-)

M
0
 

Expert Comment

by:tmattoneill
ID: 2145822
You're using the object incoorectly.

Try
      dim wrd
      set wrd = CreateObject("Word.document")
      
      wrd.Application.Visible = true
0
 

Expert Comment

by:tmattoneill
ID: 2145838
To see that it works, try this little guy...

<%@ Language=VBScript %>
<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
</HEAD>
<BODY>
<P> </P>
<%
      dim wrd
      dim wrdVer
      
      docName = "test.doc"
      set wrd = CreateObject("Word.document")
      
      wrdVer = wrd.Application.Version
      wrdName = wrd.Application.Name
      
      Response.Write("The installed version of " & wrdName & " is: " & wrdVer)
      
      
%>
</BODY>
</HTML>
0
 

Accepted Solution

by:
tmattoneill earned 80 total points
ID: 2145841
And I believe that answers your question.  You'll have to become more familiar with the word object to use the props and meths...

M
0
 

Author Comment

by:mtomkins
ID: 2145870
Now get error message:Object doesn't support this property or method 'wrd.Documents'. Thanks for all your help though. Having a problem delivering those apples now as the submit page is telling mt to contact their tech support. You will get them as soon as I can find out what the hell is wrong. Thanks again tmattoneill.
0
 

Expert Comment

by:tmattoneill
ID: 2145879
Use the GetObject function when there is a current instance of the object or if you want to create the object with a file already loaded. If there is no current instance, and you don't want the object started with a file loaded, use the CreateObject function.
0
 

Expert Comment

by:tmattoneill
ID: 2145887
That's because there is no property or method called "Documents"  Use GetObject to open an existing file.

M
0
 

Author Comment

by:mtomkins
ID: 2145893
Hope this works, cheers.
0
 
LVL 5

Expert Comment

by:mayhew
ID: 2145896
If you want to keep it at the application level, I believe you can use:

Set wrd = CreateObject("WORD.APPLICATION")

I've done this before, but I can't remember for sure what the syntax was.  I'll look it up and let you know for sure.
0
 
LVL 5

Expert Comment

by:mayhew
ID: 2145913
Sorry guys,

I should have refreshed.  Didn't realize you had it worked out.

But creating an application object instead of document object will open up the documents collection for you.
0
 

Expert Comment

by:tmattoneill
ID: 2145939
That's right.  But it's 6 of 1 etc...
0
 

Expert Comment

by:tmattoneill
ID: 2145964
That's right.  But it's 6 of 1 etc...
0

Featured Post

Understanding Web Applications

Without even knowing it, most of us are using web applications on a daily basis. Gmail and Yahoo email, Twitter, Facebook, and eBay are used by most of us daily—and they are web applications. We often confuse these web applications tools for websites.  So, what is the difference?

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

FAQ pages provide a simple way for you to supply and for customers to find answers to the most common questions about your company. Here are six reasons why your company website should have a FAQ page
Ready to get certified? Check out some courses that help you prepare for third-party exams.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will get a basic understanding of what section 508 compliance can entail, learn about skip navigation links, alt text, transcripts, and font size controls.
Suggested Courses

704 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