Solved

problems using "MS word" objects form VB5 app

Posted on 1998-02-27
4
283 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
  • 2
  • 2
4 Comments
 
LVL 6

Accepted Solution

by:
anthonyc earned 100 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
I tried the Word 8 lib and it worked so far. Thanks.
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

728 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now