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

x
?
Solved

problems using "MS word" objects form VB5 app

Posted on 1998-02-27
4
Medium Priority
?
291 Views
Last Modified: 2008-03-10
I am writing a VB app which create/manipulates a word 97 document. I have successfully been able to use the "createobject" function to insert text into a new word document. Now I need to search the document and replace certain words, but the "find" method does not work for me. I also cannot seem to use the "activedocument" object without an error. I have done the following:

     Dim word as object
     Set word = CreateObject("word.application")

    ' Make word visible through the Application object
    word.Application.Visible = True
    word.Documents.Open "C:\test.doc"
     
    If Option1(0).Value = True Then
        word.Application.selection.InsertFile filename:= mypath & "new.doc", Link:=True


*Here is where things don't work*
With word.selection.Find
        .clearformatting
        .Text = "something"
        .Replacement.clearformatting
        .Replacement.Text = myform.Text1.Text
        .Execute Replace:=wdReplaceAll, Forward:=True, Wrap:=wdFindContinue
    End With
0
Comment
Question by:englm
[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
  • 2
  • 2
4 Comments
 
LVL 6

Accepted Solution

by:
anthonyc earned 400 total points
ID: 1458066
Take a look at 3 things:

1) Make sure you have a reference in your project to the word library.  If you don't, the constants you are using will not work (wdReplaceAll and wdFindContinue will not be there correct values)

2)  Replace .replacement.text = myform.text1.text with
            .replacement.text = trim$(myform.text1.text) 'explicit conversion to text

3)  Try without the WITH statement.  Some objects do not work correctly with it.  For example, the LINE method of a picturebox does not work will with the WITH statement
0
 

Author Comment

by:englm
ID: 1458067
In your answer:

1) Make sure you have a reference in your project to the word library.  If you don't, the constants you are                   using will not work (wdReplaceAll and wdFindContinue will not be there correct values)

Question:

1. What is the reference that needs to be selected for the word library? Is it the VBA reference?



0
 
LVL 6

Expert Comment

by:anthonyc
ID: 1458068
Word 97 Object Library ( I dont have word 97, so check to see if this exists) and if not, Office 97 object library or Word 8 object lib or Office 8 object lib.
0
 

Author Comment

by:englm
ID: 1458069
I tried the Word 8 lib and it worked so far. Thanks.
0

Featured Post

Technology Partners: 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!

Question has a verified solution.

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

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

661 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